Feb 08 2011

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

Published by at 6:43 pm under ffmpeg,linux,Recommended,tips,video

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.

Share

5 responses so far

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

  1. Hristoon 09 Feb 2011 at 2:16 pm

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

  2. Royon 09 Feb 2011 at 2:32 pm

    @Hristo - updated, thanks for the fix!

  3. Edon 24 Jul 2011 at 6:00 pm

    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"

  4. guydrupalon 13 Dec 2011 at 2:40 pm

    Hi,

    The conversion not working

    Showing error "VF is not available.

    thanks

  5. Lauraon 26 Jan 2014 at 12:35 am

    Thank you! Got very frustrated trying to do this until I found your instructions

Trackback URI | Comments RSS

Leave a Reply