Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stream method to identify a video's rotation. #670

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/FFMpeg/FFProbe/DataMapping/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ public function getDimensions()
return new Dimension($width, $height);
}

/**
* Returns the rotation of the video stream, in degrees.
* Use this to determine if the dimensions are rotated.
*
* @return Integer
*
* @throws LogicException In case the stream is not a video stream.
*/
public function getRotation()
{
if (!$this->isVideo()) {
throw new LogicException('Rotation can only be retrieved from video streams.');
}
$tags = $this->get('tags');
if(empty($tags['rotate'])) return 0;
return intval($tags['rotate']);
}

/**
* Extracts a ratio from a string in a \d+:\d+ format given a key name.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/FFProbe/DataMapping/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,20 @@ public function providePropertiesForDimensionsExtraction()
),
);
}

public function testGetRotationFromVideo()
{
$stream = new Stream(array(
'codec_type' => 'video',
'tags' => array()
));
$this->assertEquals(0, $stream->getRotation());

$stream = new Stream(array(
'codec_type' => 'video',
'tags' => array('rotate' => 90)
));
$this->assertEquals(90, $stream->getRotation());
}

}