This is an old revision of the document!


mencoder

Back when I was using it, mencoder was poorly maintained, but I think that has changed in recent years. I never had much luck getting mencoder to do what I want consistently across all my DVD library, so I gave up on it, and use it in scripts mostly to get metadata. Now I use HandBrake exclusively for any ripping/encoding from DVDs.

archives: mencoder notes

# Variable framerate notes (@#$&*)

Some movies are encoded with variable fps. They will switch from NTSC to PAL and back and forth. I'm having a *hard* time finding anything that works for these.

Some ideas though:

- force the incoming fps and/or outcoming fps - try -mc 0 and/or -noskip with mencoder (the opposite being -vf harddup=1)

Positive results:

(movie starts at 29.97, but switches immediately to 23.97) mencoder movie.vob -aid 128 -ovc lavc -oac copy -o movie.avi -mc 0 -noskip -fps 24000/1001

comes close, same scenario: transcode -i movie.vob -o transcode.avi -a 0 -b 128,0,0 -w 2200,250,100 -A -N 0x2000 -M 2 -Y 4,4,4,4 -B 1,11,8 -R 0 -x vob,vob -y xvid4 -f 0,1

Something to try: audio delay (-audio-delay on mencoder, test float value with mplayer -delay 0.2 movie.avi)

mencoder basics:

Note: For old and/or crappy looking videos, XviD preserves the quality better than lavc (though it will take about 5x longer to convert, it's worth it).

example: mencoder video.wmv -o video.avi -ovc lavc -oac mp3lame -fps 29.97

example notes: -oac lavc uses mp2 by default as audio. I've found my files are smaller using -oac mp3lame each time. -ovc lavc uses divx4. Use -fps 29.97 since that's the NTSC standard framerate. Encoding at another framerate sometimes makes the video fuzzy (wmv → avi).

“-of” sets the format type, default is “avi”. Other type you would use is “mpeg”.

“-oac” is the audio codec to use. No default is set. Options are “copy” (use the old codec), “pcm” (uncompressed), “mp3lame” and “lavc” (another audio codec).

“-ovc” is the video codec to use. No default is set. Options I would use are “copy” (use old codec, don't re-encode), “divx4” (div4/5), “lavc” (supposedly best quality) and “xvid” (open source mpeg4 codec).

using “-lavcopts”:

I see a lot of examples that needlessy add “-lavcopts vcodec=mpeg4”, when the default video codec already is mpeg4 (and the best one too use). There's no reason to change the default.

You can use lavcopts to do a three pass encoding to improve the quailty.

rm frameno.avi mencoder input.avi -ovc frameno -o frameno.avi -oac mp3lame -lameopts vbr=3 mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o output.avi mencoder input.avi -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o output.avi

# encode from wmv → avi mencoder video.wmv -o video.avi -ovc lavc -oac mp3lame -fps 29.97

# rip DVD 2-pass encode of a DVD to an MPEG4 (“DivX”) AVI while encoding the audio track to MP3.

mencoder dvd:2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac mp3lame -lameopts vbr=3 -o movie.avi mencoder dvd:2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac mp3lame -lameopts vbr=3 -o movie.avi

# XviD 2-pass

mencoder dvd: -ovc xvid -oac copy -xvidencopts pass=1:vhq=1 # encode only so much use “-endpos <secs>” to test if the encoding is going to work. :) # detect aspect ratio for DVDs mplayer dvd:1 -vf cropdetect

* Mencoder + XviD

Does mencoder ignore my xvidencopts flags?? Anytime I pass a bitrate=foo value, it ignores it completely and seems to want to set it to it's own value. Kind of odd.

* images

mencoder mf:image.jpg -ofps 25 -mf fps=.002:type=jpg -ovc lavc -vf harddup -oac copy -of avi -o output.avi -audiofile audio.mp3 # Expanding Some videos (PAL DVDs, often) will come in 4:3 aspect with squished displays. You need to expand it so it has black bars at top/bottom. Pretty simple, but you have to reencode the video with mencoder. mencoder foo.mpg -vf expand=320:::::4/3 Using a width smaller than the input will just make it fill to that aspect ratio.