Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/theme.php on line 623
Niklas blog » Blog Archive » Rotating video clips shot in "portrait" mode

Niklas blog

Just another WordPress weblog

Rotating video clips shot in "portrait" mode

July 28th, 2006 in Uncategorized

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

When using my Canon IXUS 40 digital camera to record short videos I sometimes accidently rotate the camera 90 degrees. Of course this isn’t a problem when taking photos since it’s very simple to rotate an image using Photoshop, GIMP, ImageMagick, etc.

The solution might seem less obvious when dealing with video files. Fortunately, there’s this great tool called mencoder (which is part of MPlayer) which let’s us fix things like this:

mencoder -ovc lavc -lavcopts vcodec=mjpeg -vop rotate=1 -oac copy input.avi -o tmp1.avi

This works well for my kind of camera which saves video as MJPEG in 320×240 resolution. The resulting file tmp1.avi will in my case be a 240×320 MJPEG clip.

Now 240×320 is quite an odd aspect ration (3:4). mencoder fix this too:

mencoder -ovc lavc -lavcopts vcodec=mjpeg -vop expand=427:320 -oac copy tmp1.avi -o tmp2.avi
mencoder -ovc lavc -lavcopts vcodec=mjpeg -vop scale=320:240 -oac copy tmp2.avi -o output.avi

The first command will expand the video to 427×320 which is roughly 4:3. The video will be placed in the center and black borders will be added to the left and right sides.

The final command scales the video down to 320×240. Please note that this step lowers the quality of the video. But if you want to playback the video on something like a standalone DVD player you might have to use a standard resolution like this one.

Congratulations! You now have a nice 320×240 video clip.

11 Responses to “Rotating video clips shot in "portrait" mode”

  • niklas
    July 30th, 2006 at 14:00

    It turns out that Windows Media Player cannot play MJPEG files produced by mencoder. When playing the mencoder produced file using mplayer I see the following on the console:

    [mjpeg @ 0x86fd3e8]mjpeg: using external huffman table

    which I don’t see when playing the original file. I found a fix for this problem on the MPlayer mailing list which involves running the mencoder produced file through ffmpeg:

    ffmpeg -i output.avi -sameq -acodec pcm_u8 -vcodec mjpeg output_wmp.avi

    // Niklas

  • jonny
    August 30th, 2006 at 20:25

    i have recored video’s from my mobile (samsung D600) in vertical and i what to change them to play horizontal. can someone help me plz, email me on jonathonmcallister2@hotmail.com thanks

  • gene
    February 2nd, 2007 at 21:38

    I just commented that I didn’t know your OS, but doing everything from a command-line rather than with a mouse (-ovc lavc -lavcopts vcodec=mjpeg -vop rotate=1 -oac copy input.avi -o tmp1.avi) makes it clearer.

    Gene
    wikidpad.com

  • Adam Dempsey
    August 23rd, 2007 at 14:37

    Thanks :D That was exactly what I needed!

  • Hartmut
    November 21st, 2007 at 13:18

    Is the rotation lossless?
    Since MJPEG is only a sequence of jpeg images each of which can be lossless rotated, it’s definetely possible.
    But - is this case when using mencoder?

    Hartmut

  • Jonar
    August 28th, 2008 at 20:45

    Open in Quicktime pro. ctrl J and select video, and it’s a button there to rotate. Save as self contained and it will not be re-encoded.

  • Andrew Abogado
    July 20th, 2009 at 17:57

    I haven’t had a great luck on rotating a video but your tip was quite the solution I’ve been looking for.

    I tried Avidemux and somehow made the rotate but the audio doesn’t sync well.

    Here’s what I’ve used on Ubuntu 8.10 platform:

    mencoder -ovc lavc -lavcopts vcodec=mjpeg -vf rotate=1 -oac pcm tmp1.avi -o tmp2.avi

  • Andrew Price
    July 24th, 2009 at 08:44

    This just helped me out!! Thanks so much. :)

  • daniel
    November 5th, 2009 at 22:40

    hi

    I tried the command mencoder -ovc lavc -lavcopts vcodec=mjpeg -vf rotate=1 -oac copy input.flv -o output.avi
    but the audio came out qll scrambled :( ?

  • Angelo
    January 24th, 2010 at 19:51

    Hey Niklas,
    many thanks for your tips! It was exactly what I was looking for!
    I needed to rotate videos taken with my Canon FS100, which provides a resolution of 720×576. Here are my commands for such resolution:

    Rotate a video 720×576 from portrait to landscape mode

    > mencoder -ovc lavc -lavcopts vcodec=mjpeg -vf rotate=1 -oac copy -o
    > mencoder -ovc lavc -lavcopts vcodec=mjpeg -vf expand=1280:720 -oac copy -o
    > mencoder -ovc lavc -lavcopts vcodec=mjpeg -vf scale=720:576 -oac copy -o

    Great help. Thx

  • redkirk
    March 10th, 2010 at 03:41

    Tried using -vop and memcoder error was:
    -vop has been removed, use -vf instead.

    Used -vf instead. Video’s great but audio scrambled.

    How do I install vop?

    MEncoder SVN-r29237-4.4.1
    Ubuntu 9.10
    Dell Optiplex GX260, P4, 1.80GHz