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, i.e. once for each pass. It’s even more painful when your computer is over 8 years old like mine is. This is when a simple shell script comes in handy.
Configure Mencoder.conf Xvid two pass encoding
Open up ~/.mplayer/mencoder.conf in a text editor, then paste this in:
[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
###by constant bitrate
#xvidencopts=pass=1:bitrate=900:quant_type=mpeg:nogmc=yes:noqpel=yes:threads=2
[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=900:quant_type=mpeg:nogmc=yes:noqpel=yes:threads=2
If you run
mencoder -profile help
You should now see “pass1” and “pass2″ in your list of encoding profiles.
We’re not going to do any scaling so we’ll keep the original resolution.
vf=scale=-1:-1
During the first pass, we’ll use ” pass.log ” as the name of our log file. This may or may not work, depending upon your MPlayer install.
passlogfile=pass.log
For the audio part, we’ll stick with the original.
oac=copy=yes
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.
xvidencopts=pass=2:bitrate=-699000:quant_type=mpeg
Notice that when encoding by file size, a negative value is used. Also, you can pass along some other Xvid options like no GMC nor Qpel, and number of threads – great if you have more than one core/cpu to work with. *There are LOTS of other options available. Just take a look at the Mencoder / MPlayer man page and see.
Script for Xvid 2 Pass Encoding
Now using a script to do Xvid two pass encoding. 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 “$1″  -profile  pass1 -o  /dev/null &&
sleep  3  &&
mencoder “$1″ -profile  pass2  -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. There are lots of tools available. Most notable here would be xvid4conf.