Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg on iPhone - Modifying Video Orientation

I'm messing with h264 videos loaded with FFmpeg on the iPhone 3GS. The problem is any videos recorded in "Portrait" orientation have a transformation matrix applied to them causing them to display rotated 90 degrees counter-clock.

From what I understand thus far, I just need to modify the transform matrix in the 'tkhd' atom. The problem is I am having trouble accessing or modifying this data. I checked out the FFmpeg implementation for:

static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)

which clearly shows how the matrix is accessed in avformat but when I try to access the header bytes using the same functions I am not getting any rational values. Even if I were to successfully pull the matrix I'm not sure how to replace it? FFmpeg has functions for retrieving and appending to the track header but nothing for replace it seems?

Any help would be greatly appreciated.

Thanks, Matt.

like image 603
Matthew McGoogan Avatar asked Feb 05 '10 16:02

Matthew McGoogan


2 Answers

To those who cannot get the v filter option to work, after some searching I found an alternative option which works for my build:

ffmpeg -i in.avi -vf "transpose=1" out.avi

this flips the video 90 degrees clockwise. hope this helps all those on ubuntu struggling like I was!! :)

like image 87
Alex K Avatar answered Oct 13 '22 00:10

Alex K


I just had a patch accepted on the FFMPEG git master branch which should help all of us in adjusting for the iPhone's orientation and subsequent transform applied to the .mov file it sends out. FFMPEG will now send back in metadata:

'rotate'=90,180,or 270 depending on how many degrees you need to turn the image clockwise to get the true rotation.

like image 20
Piotr Tomasik Avatar answered Oct 13 '22 00:10

Piotr Tomasik