简体   繁体   English

从服务器检测iPhone视频的方向

[英]Detect orientation of an iPhone video from server

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). 我试图检测通过PHP表单上传的iPhone视频文件(.mov)的方向,以便我可以使用FFMPEG对其进行纠正(很多上传的视频都显示在它们的侧面)。 I can not seem to find a way of accessing the orientation of the uploaded file on the server. 我似乎找不到找到访问服务器上已上传文件方向的方法。 Any ideas? 有任何想法吗?

Using mediainfo 使用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): 您可以使用exec()捕获此系统调用的输出,并应用方向定位(顺时针90度):

$ ffmpeg -i test.mp4 -vf "transpose=1" testRotated.mp4

If you have --enable_vfilters 如果您具有--enable_vfilters

$ ffmpeg -vfilters "rotate=90" -i test.mp4 testRotated.mp4

I'm not the best with regex but here is how I would go about doing it 我不是使用regex最好的人,但是这就是我要做的事情

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. 然后检查$ dims [1]是否大于$ dims [2],如果是则表示横向,如果小于纵向。

I wasn't able to test it fully but something along those lines should work for you. 我无法对其进行完整的测试,但是按照这些原则进行的工作应该适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM