Updated Mencoder Script
Welcome!
A while back I wrote a script to convert my dvd collection into AVI files on my computer, which included the ability to auto-crop the black borders. I recently decided I wanted to start using the Matroska container instead of AVI. I again tried to accomplish this with GUI tools – many of them I evaluated previously such as WinFF and HyperVC and I also tried Avidemux and HandBrake GTK. WinFF/HyperVC wouldn’t run the encode for some reason when I selected the auto-crop features, and HandBrake GTK would not run at all on Karmic Koala giving GTK errors. Avidemux allowed me to set all the settings, and it worked – but the audio was invariably a-sync’d. I couldn’t find any settings with MP3, Vorbis, or FAAC that would properly sync with the video I was trying to convert.
So once again I had to resort to building my own. I use the same cropdetect.sh that is in my previous post and have just modified my mconverter.sh file to this:
#!/bin/sh
for video in $@; do
name=${video%\.*}
echo "Getting Crop Size"
crop=`cropdetect.sh $video | awk -F 'crop=' '/crop/ {print $2}'`
crop=`echo $crop|sed 's/^[ ]*//'`
echo "Starting Pass 1"
`which mencoder` "$video" -nosound -ovc x264 -x264encopts
bitrate=1800:subq=5:bframes=3:
b_pyramid:weight_b:turbo=1:threads=4:pass=1
-passlogfile "$name.log" -o /dev/null -vf
pullup,softskip,crop=$crop,harddup
echo "Starting Pass 2"
`which mencoder` "$video" -nosound -ovc x264 -x264encopts
bitrate=1800:subq=5:8x8dct:frameref=2:bframes=3:
b_pyramid:weight_b:threads=4:pass=2
-lameopts vbr=2:br=192:aq=3 -passlogfile "$name.log" -o
"$name.264" -vf pullup,softskip,crop=$crop,harddup
echo "Creating Audio"
`which mencoder` "$video" -alang "en" -ovc frameno -oac lavc -lavcopts acodec=vorbis:abitrate=224 -channels 2 -srate 48000 -o "audio.avi"
echo "Creating MKV"
`which mkvmerge` -D "audio.avi" -A "$name.264" -o "$name.mkv"
done
This creates a MKV file using mencoder and mkvmerge (from mkvtoolnix) with the same name as the input file that has an h.264 encoded video at 1800 bitrate and a vorbis encoded audio with 2 channels. In my tests this has worked perfectly in providing sync’d audio and video and giving me good quality while saving space. A 6.6GB movie was compressed to 1.6GB with these settings and I can barely tell the difference when pausing the video’s side-by-side.
This is just another post that is more of a note for me in case I lose my scripts, but hopefully someone else out there manages to find use for it.
Happy Encoding!

Leave a Reply
You must be logged in to post a comment.