问题
I am attempting to detect the orientation of an iPhone video file (.mov) on upload through a PHP form so that I can use FFMPEG to correct it (a lot of the videos uploaded are shown on their side). I can not seem to find a way of accessing the orientation of the uploaded file on the server. Any ideas?
回答1:
Using mediainfo
$ mediainfo test.mp4 | grep Rotation
Rotation : 90°
You can use exec() to capture the output of this system call, and apply the orientation fix (90 degrees clockwise):
$ ffmpeg -i test.mp4 -vf "transpose=1" testRotated.mp4
If you have --enable_vfilters
$ ffmpeg -vfilters "rotate=90" -i test.mp4 testRotated.mp4
回答2:
I'm not the best with regex but here is how I would go about doing it
exec(ffmpeg -i uploaded.mov,$output)
Then once you have the output do a pregmatch on it, like so
preg_match('/(\d+)x(\d+)/', $output, $dims);
Then check to see if $dims[1] is greater than $dims[2], if it is then it's in landscape, if it's less than its in portrait.
I wasn't able to test it fully but something along those lines should work for you.
来源:https://stackoverflow.com/questions/9334176/detect-orientation-of-an-iphone-video-from-server