Technical

Tech Tip #5: Rotate a video by 90 degrees with mencoder

I was recently doing some video editing work where the workflow was something like this: film in portrait, transfer to computer, rotate videos by 90 degrees, sequence together several videos, strip out background noise from entire video. Filming was done with a camera, sequencing was done by Kdenlive (I’ve previously only had experience with Blender’s VSE and I must say I was very happy with this new application), and the noise-stripping was done with Audacity. I must say I’m surprised at how fast this was all accomplished and kudos to all those developers who created these apps.

However one thing I didn’t know how to do was how to rotate the video by 90 degrees. Kdenlive can do it but it ends up being awkwardly stretched and I couldn’t figure out how to unstretch it. Luckily mencoder, which comes with the mplayer package, has got a few tricks up its sleeve.

More for my own records than for anybody else, here’s the command I used:

mencoder -vf rotate=2 -o output.avi -oac pcm -ovc lavc input.mov

As my input file was a .mov some of the sound wasn’t synchronised well after rotating, which was easily fixed by this option -demuxer mov. If you want to rotate clockwise instead of anticlockwise change rotate=2 to rotate=1.

Dion Moult

I've been developing software for well over 10 years, work as an architect (not the computer kind, the regular sort), and am classically trained as a pianist. I try to do the right thing when I get the chance in my field, such as through contributing to open-source communities and promoting sustainable living.

More Posts

Spread the love
Tagged: , , , , ,

7 Comments

  1. Great little tip, I have videos that have been shot sideways and its always frustrating when I realize that is the case. I’ll have to note this page for later! Thanks.

    Yeah, KDEnlive is a nifty app eh? Its come a long way over the years. I remember its pre-0.5 days, it was almost unusable…. now at 0.7.1 or something, it is doing quite well.

  2. Cheers, yeah I’ve also heard that KDEnlive has really improved. I did stumble upon a showstopper bug though, it turns out that <0.7.7 when compiled against Qt 4.6 doesn't work at all.

    For those interested, here is the command I used to strip audio from the file (should be codec independent I think):
    mplayer input.avi -vo null -ao pcm:file=audio.wav:fast

    ... and then after noise removing in Audacity and exporting as an mp3, you can replace the original audio track of the avi with your improved mp3 with this command:
    ffmpeg -i input.avi -i audio.mp3 -map 0.0:1 -map 1:0 -f avi -vcodec copy -acodec copy output.avi

    Wonderful stuff, all this ffmpeg, mplayer and mencoder. 'Cept I can never really be bothered to RTFM for all these options.

  3. AWESOME THANK YOU! After trying to figure out how to do this with KDEnlive for who knows how long, this simple terminal command did the trick nicely!

  4. Hi,
    Thanks for the tip, but it appears that the output is about 10 times lighter, and the quality of the vid is so degraded.
    Any tip to keep the quality unchanged?

  5. get stuck with no particular error :
    libavcodec (360×480 fourcc=34504d46 [FMP4])

    mov from ipahone I guess

  6. You can actually do a direct copy instead of re-encoding.

    mencoder -vf rotate=2 -o output.avi -oac copy -ovc copy input.mov

Leave a Reply

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