Howto convert AVI to xvid with mencoder
As I was looking into reducing the size of a video, I felt upon this wiki page, which proved super-useful:
Note: As commented by one reader, xvid is not really divx though, but changing the title and the url of my post 6 months later would just add to the confusion. Sorry about that, I wasn’t meaning to confuse anyone, and I thought in good fait it was the same (the results are the same for me though: very high volume loss for very little quality loss).
In short, you can use something like this for a quick fix:
mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts bitrate=687 -o <output.avi>
or maybe something like this:
mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -o <output.avi>
(setting a negative bitrate lets mencoder calculate the bitrate automatically to reach a file size of the given negative value in KiloBytes, although this doesn’t work for me…)
If you want to resize your video to something smaller, say 320×240 pixels (because you don’t need all that quality to upload it on youtube, in the end), you might consider using the video filter (vf) “scale” like so:
mencoder <filename.avi> -ovc xvid -oac mp3lame -xvidencopts bitrate=-700000 -vf scale=320:240 -o <output.avi>
Another bit of mencoder magic that is really practical is that joining little videos is really easy. In fact, you just have to give an input (with multiple files) and an output (a single file) and mencoder will understand you want to join them:
mencoder <f1.avi> <f2.avi> <f3.avi> -ovc copy -oac copy -o <output.avi>
The “copy” instructions is to make sure it uses the same codec that is currently used for the three videos. Of course, those three should be in the same format…
To do the opposite (let’s say you want to split a video in chunks of 10 minutes to upload them on youtube), you can extract bits using -ss 0 and -endpos 600 where -ss represents the second we want mencoder to start the chunk at, and -endpos represents the second we want mencoder to stop the chunk at. Like so:
mencoder <f1.avi> -ovc copy -oac copy -ss 0 -endpos 600 -o <chunk1.avi>mencoder <f1.avi> -ovc copy -oac copy -ss 600 -endpos 1200 -o <chunk2.avi>
Use the “-idx” option if you have a RAW AVI file format, or the cut doesn’t start from the -ss position as it should. That’s it for now.