Categories
ffmpeg linux Recommended tips video

How to rotate a video using MEncoder and FFmpeg and live to tell the tale

Hi
I’d like to share a quick tip on rotating video files.
I’m always frustrated with taking videos with my phone. Single handedly it’s easiest to do it when the phone is upright and not in landscape mode. But the files are always saved in landscape mode, which makes them rotated when you watch.
Although there are plenty of GUI software to do it, using the command line is faster and can also be batched!

Using FFmpeg

This is the basic syntax
./ffmpeg -vf transpose=0 -i input.mp4 output.avi
Just using -vf transpose=0 to rotate 90 deg clockwise. If you get the “Unrecognized option ‘vf'” error, you need to configure & build ffmpeg with --enable-filters (or at least without --disable-filters), and check with ffmpeg -filters that you get them to show up.
Also, I always get very lousy video quality when using the plain vanilla settings. It turns out the problem is with the frame rate. If you leave it as-is the (default) mpeg compression makes a lot of I and P frames, and too few B frames. So set it up explicitly.
I ended up with
ffmpeg -vf transpose=0 -i input.mp4 -r 30 output.avi
Easy.
Update [3/1/11]: Actually just using -vf transpose=0 will flip the video horizontally as well, which is undesirable in some cases. To counter that I use: -vf "transpose=0,hflip=0", and it resolves the problem.

Using MEncoder

Again, pretty simple thing to do:
mencoder input.mp4 -nosound -o characters-resize-turn.avi -vf rotate=0 -ovc lavc -lavcopts vcodec=mpeg4 -ofps 30
Note that I kill the audio with -nosound, and again set the frame rate-ofps 30 or else I get the “duplicate frames” problem.
Enjoy
Roy.

5 replies on “How to rotate a video using MEncoder and FFmpeg and live to tell the tale”

Thanks for the tips!
A note about mencoder: “-nosound”, or “-noaudio”, also, “-ofps”, or “-ofs” ?
Your command line and description differ.

I added “-vcodec copy” and it ran through the video very quickly.
N:\Digital Photos\2011-07-24 time lapse>ffmpeg -i IMG_4092.MOV -vf “transpose=0,hflip=0” -an -vcodec copy “doing dishes.mov”

Leave a Reply

Your email address will not be published. Required fields are marked *