UNIX Scripts Bash Tips: transcoding converting video files Part 3
If you’ve read part 2, then you should now be familiar with mencoder.conf and using profiles when converting video files using Mencoder. We now take it a step further with Xvid two pass encoding using a shell script.
I find doing Xvid two pass encoding on the command line a pain, since you need to do the transcoding twice. It’s even more painful when your computer is over 8 years old like mine is. This is where a shell script comes in handy.
Configure Mencoder.conf Xvid two pass encoding
During the first pass, we’ll use ” pass.log ” as the name of our log file. For the audio part, we’ll stick with the original. The video part will be encoded based on an estimate of the final file size of 700MB. However, we can also do so based on a given constant bitrate.
[pass1]
vf=scale=-1:-1
passlogfile=pass.log
oac=copy=yes
ffourcc=XVID
ovc=xvid=yes
###by final file size, usually works: either 700 MB or 400 MB
xvidencopts=pass=1:quant_type=mpeg
#xvidencopts=pass=1:quant_type=mpeg
###by constant bitrate, usually works
#xvidencopts=pass=1:bitrate=900:quant_type=mpeg
[pass2]
vf=scale=-1:-1
passlogfile=pass.log
oac=copy=yes
ffourcc=XVID
ovc=xvid=yes
xvidencopts=pass=2:bitrate=-699000:quant_type=mpeg
#xvidencopts=pass=2:bitrate=-390000:quant_type=mpeg
#xvidencopts=pass=2:bitrate=900:quant_type=mpeg
Xvid 2 Pass Encoding Using a Shell Script
Now doing the Xvid two pass encoding using a shell script. We put this in a file called ” 2pass.sh ” in the working directory. Be sure to have enough disk space. Alternatively, put it in your $HOME/bin directory - if you’ve made it executable, and “chmod 700″ it.
#!/bin/sh
mencoder -profile pass1 ”$1″ -o /dev/null &&
sleep 3 &&
mencoder -profile pass2 ”$1″ -o pass2_”$1″
I put in the ” sleep ” command to give my ancient PC a rest after each run.
Then we run:
sh 2pass.sh OLD.avi
When it’s finished running, we have two files:
pass.log
pass2_OLD.avi
The second one is the new video. You may want to test the file size setting, as this configuration is less than perfect.

Leave a Comment