Fixing sideways videos from i-phone

The other day I ran into a problem which is becoming increasingly common – how to right a video, taken from an iphone, which displays on its side?

I do most of my video conversions with ffmpeg, but the version I have doesn’t have any support for rotating videos (though it does have the possibility of horizontal or vertical flipping), so I had to turn to the useful MEncoder tool included with Mplayer.

The presumption here is that you’re working on windows:

  • Step 1download the win-32 build and extract it to your local drive (maybe changing the long folder name,, to something easier like mplayer – to make it easier in the command line)
  • Step 2 –  copy your sideways video to your mplayer folder
  • Step 3 – go to your windows start menu and enter in cmd into the search box, and hit enter. This will launch the command line tool
  • Step 4 – type in chdir c:mplayer   (or whatever folder you’ve unpacked the mplayer tools and sideways video to) to go to the directory where we’ll be doing the rotation

Now we’re going to run a very simple command to rotate the video – there are plenty of other options that you can use, but for the purpose of this we’re just interested in rotating the video 90°

  • Step 5 – the bit where the magic happens! – now we’re going to run the MEncoder using the following line: mencoder -vf rotate=1 -o rotated-file.avi -oac copy -ovc lavc

Now to explain some of the above.
-vf means video filter

-o stands for the output file MEncoder will create a new file for you based on what you name here.

rotate is the main filter we’re using. It takes a numeric value for as follows:
0 -> 90 Degree Clockwise + Mirrored
* 1-> 90 Degree Clockwise
* 2-> 90 Degree Anticlockwise
* 3-> 90 Degree Anticlockwise + Mirrored

-oac stands for output audio codec. In the above example we’re copying the audio codec from the input file to the output. You may come across an error here if there’s a conflict, in which case you can substitute -oac pcm for -oac copy (see more information here)

-ovc stands for output video codec, and lavc is an ffmpeg library which should do the job fine for you (see more information on video codecs here)

So that’s it. Run the command line, and after a minute or two, depending obviously upon the size of your video, you should find your new video file which will show the right way up!


Tags: , ,