Home > English, General, Techie > Howto convert AVI to xvid with mencoder

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:

HOWTO Convert video files

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.

  1. ywarnier
  2. Chris
    January 15, 2009 at 12:21 am

    xvid is not DIVX… title is misleading… i’m looking for how to convert xvid to divx on linux

  3. Dan
    May 17, 2009 at 6:18 am

    Yeah. Change the title. As chris said, xvid is not divx and i too was looking for divx.

    • ywarnier
      May 17, 2009 at 9:38 am

      Done. Sorry about the confusion

  4. July 28, 2009 at 3:39 pm

    Thanks for you hint. you can add -af volnorm to tell mencoder to normalize the sound too :)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: