views:

2361

answers:

4

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.

+1  A: 

Portrait video recorded in iPhone 3GS is strangely rotated in landscape, and only quicktime plays it correctly, players like VLC etc play the portrait mode videos in landscape because it is encoded that way! Maybe apple have set some bit so that quicktime identifies and sets the orientation properly.

You can use -vfilters option of ffmpeg to rotate the video. It is available in version r21242. You have to patch it on your version of ffmpeg.

configure the build by using --enable-vfilters

and you can use the option:

ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4

to rotate the input movie.

Raj
Thanks Raj. I'm doing development with the FFmpeg library though so using ffmpeg as a command line program is not an option. I have to find a way using their source library.
Matthew McGoogan
Matthew,@"I'm doing development with the FFmpeg library"I know and the purpose of this post is the same! You create command line arguments with the options as shown above and pass it to ffmpeg main() method. The rest will be done by ffmpeg itself. You have to include ffmpeg.c file into your project and also static libraries which is created by using appropriate configuration command, which I hope is already done.
Raj
A: 

Hello Raj,

Can you please tell me which version of ffmpeg is used to execute this command

 ffmpeg -vfilters "rotate=90" -i input.mp4 output.mp4 I have used it but 

video is not rotating.

A: 

All, I've searched high and low and can't find a version of ffmpeg with the vfilters option. Don't believe everything you read on the internet.

Mike Wright
A: 

Raj

Is it possible to see some code with command line arguments passed to FFmpeg?? I get a compile error if i include ffmpeg.c in my project.