After surfing through tons of documentation on the web it seems that the iPhone always shoots the video at a 480x360 aspect ratio and applies a transformation matrix on the video track. (480x360 may change but its always the same for a given device)
Here is a way of modifying the ffmpeg source within a iOS project and accessing the matrix http://www.seqoy.com/correct-orientation-for-iphone-recorded-movies-with-ffmpeg/
Here is a cleaner way of finding the transformation matrix in iOS-4 How to detect (iPhone SDK) if a video file was recorded in portrait orientation, or landscape.
How can the orientation of the video be extracted in either of the options below -
- iOS 3.2
- ffmpeg (through the command line server side)
- ruby
Any help will be appreciated.
From what I've found thus far, ffmpeg doesn't have the ability to detect iPhone's orientation. But, the open source library, mediainfo can. A command line example:
More example output from the same iphone video:
Similar to @HdN8's answer, but without the python regex:
Or JSON:
Or you could parse the JSON (or other output format).
You can use
ffprobe
. No need for anygrep
, or any other additional processes, or any regex operations to parse the output as shown in other answers.If you want the rotate metadata:
Command:
Example output:
If you want the display matrix rotation side data:
Command:
Example output:
If you want the display matrix:
Command:
Example output:
What the options mean
-loglevel error
Omit the header and other info from output.-select_streams v:0
Only process the first video stream and ignore everything else. Useful if your input contains multiple video streams and you only want info from one.-show_entries stream_tags=rotate
Chooses to output therotate
tag from the video stream.-of default=nw=1:nk=1
Use default output format, but omit including the section header/footer wrappers and each field key.Output format
The output from
ffprobe
can be formatted in several ways. For example, JSON:I have extracted on iOS using an AVAssetExportSession, AVMutableComposition and the input AVAssetTrack's preferredTransform. I concatenate the preferred transform with a transformation to fill the target size.
After exporting to a file, I upload using ASIHTTPRequest to my rails server and send the data to Amazon S3 using paperclip.
ffmpeg reports the metadata with the rotation value for .mov files:
....
In my application I pull it out with regex, ie in python:
I havent tried this with a wide range of videos, only a couple .movs recorded from an iphone5, using ffmpeg version 1.0. But so far so good.
Since most Cameras store their rotation/orientation within the exif-metadata, i would suggest using
exifttool
and the a ruby wrapper gem calledmini_exiftool
which is actively maintained.Install exiftool:
apt-get exiftool || brew install exiftool || port install exiftool
or use what ever package manager is available
Install mini_exiftool:
gem install mini_exiftool
Try it:
cheers