How to rotate an AVI or MPEG file taken in Portrait
I've got a little Casio Exilim that I use to make little videos to post on this blog. Sometimes, though, I rotate the camera and end up creating a video that's, well, rotated in portrait, not landscape, and I want to rotate the Video to a vertical orientation.
There's an open source tool called MPlayer out of Hungary that you can download. Get the MPlayer 1.0rc1 Windows package, NOT the Windows GUI package. We're not looking for a Video Player here but rather a utility called MEncoder that comes with the MPlayer package.
This command-line tool is rather obscure, as it seems is the whole culture of video wonks, but I just want to do my work and move on. If you like, however, there's a whole world of Unofficial Packages that sit in front of this obscure tool and do the hard work for you.
Here's the magic I used to rotate my video 90 degrees to the right:
C:\Users\Scott\Desktop\mplayer>
mencoder -vf rotate=1 -o OUTPUT.AVI -oac copy -ovc lavc INPUT.AVI
The -vf is for "Video Filter" and you can chain them, like -vf rotate=1,flip,scale=640:480 if you like. The -oac and -ovc are the audio and video outputs. In this case, I "copy" the audio over, and use the "libavcodecs" for the output. You can do mencoder -ovc help to get a list of choices or read the massive docs.
At this point, I have a really tall 480x640 video, since it used to be at 640x480. Certainly I can leave it there, or I can expand it to a more regular 4:3 ratio. As it's now 640 tall, it'll need to be 853x640 to be 4:3.
C:\Users\Scott\Desktop\mplayer>
mencoder -vop expand=853:640 -oac copy ovc lavc -lavcopts vcodec=mjpeg OUTPUT.AVI -o BIGOUTPUT.AVI
Notice that the portrait is now centered between black bars like a vertical DVD. The aspect ratio is correctish now and we have a vertically oriented video inside a horizontally oriented "container."
I probably (and you as well) should use "raw" as your output format as you move through these steps, as we're making copies of copies here and the quality is getting worse and worse. You'll end up with gigabyte-size temp files, for a bit, but your output will be much better.
Next I'll just scale the video back to 640x480 for posting on the web.
C:\Users\Scott\Desktop\mplayer>
mencoder -ovc lavc -lavcopts vcodec=mjpeg -vop scale=640:480 -oac copy BIGOUTPUT.AVI -o FINAL.AVI
Again, pick the codec that is right for you in order to tune your output size and quality.
UPDATE: Someone emailed saying that the AVI format made by mencoder doesn't always work on Windows Media. (I use VLC Player, works fine) and they suggested the final encoding pass be done by FFMPEG, rather than mencoder:
C:\Users\Scott\Desktop\mplayer>
c:\utils\ffmpeg_mp2.exe" -i finaltest.avi -sameq -acodec pcm_u8 -vcodec mjpeg FFMPEGOUTPUT.AVI
Worked for me.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Took videos of a wedding with my Olympus digital camera.
Turned camera,to get full body shots of everyone. They're beautiful,
but I get a crick in my neck when I view them. Have downloaded
various programs which are meant to rotate them, but to no avail.
Need a simple, easy to understand program I can download. Don't want
to have to buy any extra programs to assist with the video rotation,
because I'll never again turn my camera when I do videos. I have Adobe
Photoshop Elements 5.0 and Adobe Premiere Elements 3.0., and updated
Windows Media Player. Can you suggest an easy to use program I can download?
Thank you for your time and attention.
Sincerely, Marilynn
Comments are closed.
DirectShowSource("path/to.avi")
TurnLeft()
I open the .avs file in VirtualDub, and save it as a new AVI. I'm sure you can expand it to be 4:3 and resize back to 640x480 with the AviSynth script but I'm usually just uploading the video to Google Video, so I don't bother with that.