1

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?

Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
Lloyd S
  • 129
  • 1
  • 9
  • http://stackoverflow.com/questions/2814626/programatically-access-orientation-of-an-iphone-video – Charles Sprayberry Feb 17 '12 at 19:35
  • @craig1231 Huh? So, since a browser is a client it shouldn't be allowed to interact with the server running PHP? The iPhone certainly can [send requests, and data, to a webserver](http://stackoverflow.com/questions/3249897/get-content-of-webservice). – Charles Sprayberry Feb 17 '12 at 19:41
  • Sorry, just clarified the question, the user uploads the file from their pc via a html/php form – Lloyd S Feb 17 '12 at 19:42
  • 2
    You need to detect the orientation on the client (iPhone) then send that to the server and have php talk to ffmpeg – hackartist Feb 17 '12 at 19:43
  • @CharlesSprayberry PHP itself is not a webserver – craig1231 Feb 17 '12 at 20:32
  • @craig1231 Of course it isn't. But to say that a client can't interact with or send data to PHP is disingenuous. If the client had no way of sending data to PHP then PHP-powered websites wouldn't even exist. – Charles Sprayberry Feb 17 '12 at 20:39

2 Answers2

8

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
Guilherme Viebig
  • 6,901
  • 3
  • 28
  • 30
0

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.

projectxmatt
  • 3,091
  • 2
  • 15
  • 16
  • Dimensions tell you nothing about the orientation. It might work in some cases but not if you turn the camera upside down or the camera using portrait normally. – PiTheNumber Mar 17 '14 at 09:13