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

Conversation

jacobischwartz
Copy link

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets no
Related issues/PRs #117 #199
License MIT

What's in this PR?

Add a stream method to easily identify the rotation of a video.

Why?

There seems to be a common confusion regarding the dimensions of a video that have been rotated. FFProbe can report the width and height as the reverse of what the video appears to have. iPhones create portrait video that exhibit this issue, for example. But by inspecting the rotation of a video, this issue can be accounted for. By providing a getRotation method alongside the getDimensions method, it will be easier for users of this library to discover the reason for their confusion.

Here are some examples of people exhibiting this confusion, sometimes with this library, sometimes with FFProbe vanilla:
#117
https://forums.creativecow.net/docs/forums/post.php?forumid=291&postid=888&univpostid=888&pview=t
https://stackoverflow.com/questions/53339787/ffmpeg-get-orientation-inverted
#199
https://stackoverflow.com/questions/13093295/how-can-i-determine-video-rotation-orientation-in-php-ffmpeg-phonegap

Here's a help page from this library that discusses the issue. This new method is self-documenting code that would assist users who go down the same rabbit hole that I did:
https://github.com/PHP-FFMpeg/PHP-FFMpeg/wiki/How-to-rotate-video-based-on-smartphone-rotate-meta-tag

Example Usage

$stream = FFProbe::create()
        ->streams($video_filepath)
        ->videos()
        ->first();
$rotation = $stream->getRotation();
$dims = $stream->getDimensions();

// Now we can reverse dimensions
if((90 === $rotation) || (-90 === $rotation)) $dims = new Dimension($dims->getHeight(), $dims->getWidth());

@jens1o
Copy link
Member

jens1o commented Aug 16, 2019

Thanks for your contribution! Could you add a test for this, please? :)

Then I'm happy to merge this into the next minor release. :)

@jacobischwartz
Copy link
Author

@jens1o test added.

@jens1o
Copy link
Member

jens1o commented Sep 4, 2019

Thanks, I'll take a look! :)

@jens1o jens1o added the needs testing Maintainers are going to test out in real-world applications to check whether it works as expected. label Sep 4, 2019
@jens1o jens1o self-assigned this Sep 4, 2019
@jens1o jens1o self-requested a review September 4, 2019 07:58
@nickano
Copy link

nickano commented Nov 5, 2022

Hey jensto, thanks for this tweak - do you think you'll have time to fix the conflicts and get this ready for release again, as I could see it being very useful :)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs testing Maintainers are going to test out in real-world applications to check whether it works as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants