Best Mencoder Settings?


Minkoff

Member
Joined
Oct 18, 2005
Messages
212
I'm a little bit of a newbie when it comes to Mencoder and Linux in general, so I've been having trouble finding the "best" settings to encode small video files to play on the GP2X. This is the best I've been able to do:

mencoder input.avi -oac copy -ovc xvid -xvidencopts bitrate=192 -vf scale=320:240 -o output.avi

And for dual-audio (change the aid appropriately):

mencoder input.avi -oac mp3lame -aid 1 -lameopts vbr=2 -ovc xvid -xvidencopts bitrate=192 -vf scale=320:240 -o output.avi

The main problem with these settings is that in anime, things get a little choppy in action scenes. I think it's because setting the bitrate like that makes it somewhat constant. Replacing "bitrate=192" with "pass=2" seems to just make an error, and the other option (I can't think of it off the top of my head) seems a little weird to me. Oh, also, I set the bitrate to 192 because I don't really know what people tend to use for video, and it let me store two and a half hours of anime on a single 256MB SD card.
 
I have a script that does 2 pass encoding at a low bitrate. I've been using it for just about everything, it looks good with cartoons (ever so slightly blocky, but hardly noticable).

I have the audio bitrate down quite a bit. It sounds good on the gp2x speakers, I havent tried it on a set of headphones (Mine broke...).

Here's the code if you care to try it:

Code:
#!/bin/bash

#Video Bitrate - Lower == Less filesize and less quality
VBR="180"
#Audio Bitrate - Multiples of 16
ABR="48"

if [ -z $1 ]; then
        echo "Usage: $0 <inputfile> <outputfile>"
        exit 1
fi

if [ -z $2 ]; then
        echo "Usage: $0 <inputfile> <outputfile>"
        exit 1
fi

if [ -f divx2pass.log ]; then
        rm -f divx2pass.log 2>/dev/null
fi

MENCODER=`which mencoder`
#First pass
nice -n 19 \
        $MENCODER \
                -oac mp3lame \
                -ovc lavc \
                -srate 22050 \
                -lameopts cbr:br=$ABR \
                -ffourcc DIVX \
                -lavcopts vcodec=mpeg4:vbitrate=$VBR::v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:vpass=1:turbo \
                -vf scale=320:-3 \
                $1 -o $2

#Second pass
nice -n 19 \
        $MENCODER \
                -oac mp3lame \
                -ovc lavc \
                -srate 22050 \
                -lameopts cbr:br=$ABR \
                -ffourcc DIVX \
                -lavcopts vcodec=mpeg4:vbitrate=$VBR::v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:vpass=2 \
                -vf scale=320:-3 \
                $1 -o $2

Just dump that into a file, and chmod +x it. Should work.
 
Cool, thanks alot. :)
I'll try it out and see if it does much better.

EDIT: Oh, it looks like you can only do 2-pass in xvid if you set the bitrate or fixed_quant option. Gentoo wiki, you have failed me. :(
EDIT 2: Never mind, I'm an idiot.
 
Minkoff, use Avidemux whenever possible and it will make your life happy. Only works perfectly easily with single-audio AVI, but there's a lot of that around anyway...

Now, the best bet is to not bother with video bitrate, and 2-pass, while a nice idea, takes a while and is overly complicated (in comparison to my preferred option). What you need to do is use the vqscale for a quantizer setting; decent ranges are between two and six, higher number meaning lower quality. Generally, I find that while five is fine for most things, you need to use a higher setting on something if the colors are going to be dark, as most compression is accomplished by reducing color details in dark areas, as they usually don't matter.

Using Avidemux and then switching to Mencoder is easier than descending into that CLI hell cold. But at least it isn't CUPS, eh?
 
I prefer command line programs for things like this... After I learn it, it's alot faster to just type in some crap in a terminal than open up a GUI, navigate through the menus, etc. Anyway, for a folder full of OGM's, this is what I did:

Code:
for i in *.ogm;
do
echo "=========================================================================="
echo "Starting First Pass for $i"
echo "=========================================================================="
./mencoder "$i" -oac pcm -ovc xvid -vf scale=320:240 -xvidencopts pass=1 -o /dev/null
echo "=========================================================================="
echo "Starting Second Pass for $i"
echo "=========================================================================="
./mencoder "$i" -oac mp3lame -aid 1 -lameopts abr:br=96 -ovc xvid -vf scale=320:240 -xvidencopts pass=2:bitrate=192 -o "$i.avi"
echo "=========================================================================="
echo "Done with $i"
echo "=========================================================================="
rm "./xvid-twopass.stats"
done

I believe there is a way to do the first pass without re-encoding the audio (and PCM is naturally faster than LAME because it's lossless), but I was feeling lazy. The quality is quite good for the filesize. (96 + 192) * 60 * 24 / 8 = 51.8, which is a little less than what I got... either way, I can fit plenty on my SD card.
 
Back
Top