UNIX Scripts Bash Tips: transcoding converting video files Part 2
Welcome to Part 2 of trancoding and converting video files. This is a follow-up to my adventures working with a variety of software - Windows and Linux - for trancoding and converting videos.
VirtualDub and its sister VirtualDubMod have remained a constant for me on the Windows platform. This is in conjunction with Xvid as the codec of choice for compressing the video portion of my files. For the audio portion, I stick with the original source otherwise using MPEG Layer-III for compression.
On Linux (in this case, Debian as choice of distribution), I’ve delved further into Mencoder’s plethora of options through its configuration file. To be honest, it should be transocde, but I find its man page and possibilities a little too overwhelming right now.
First, when using Mencoder, you should have a few other packages installed, like MPlayer for instance. Usually this won’t be an issue, since there are a number of dependencies for it.
Second, this is all being done via the command line, so you’ll either need to go to a console or bring up an terminal window.
The basic command is simple:
mencoder old.avi -o new.avi
What’s left out are all the options you can employ. But what happens when there are so many options? and you don’t want to use the same set each time? You could write an individual shell script for each set of options, but wouldn’t it be easier to just edit a configuration file?
Mencoder.conf
After using MPlayer or Mencoder once, you should have a ” .mplayer ” folder in your home directory. This file is where you can put all your options, when it’s not convenient to do so each time you run Mencoder or in a shell script. Here’s a small sample of mine. Any options not specified revert to defaults. Extra comments appear after triple hashes.
[quant4] ###profile name
vf=scale=-1:-1 ###no scaling, use original size, i.e. resolution
oac=mp3lame=yes ###compress audio in MP3 format
lameopts=cbr=yes:br=128
###use a constant bitrate of 128 kbits/sec. for audio
ffourcc=XVID ###identify the video as being Xvid
ovc=xvid=yes ###compress video in Xvid
xvidencopts=fixed_quant=4:noqpel=yes:nogmc=yes:quant_type=mpeg ###Xvid options
subalign=2 ###place subtitles at the bottom
subfont-text-scale=3 ###size of the subtitles, use 2 for larger subtitles
subwidth=70 ###maximum width of each subtitle line
[quant2]
vf=scale=-1:-1
oac=copy=yes ###use the original audio: better quality but, larger file size
ffourcc=XVID
ovc=xvid=yes
###use a different fixed quantizer mode: better quality but, larger file size
xvidencopts=fixed_quant=2:quant_type=mpeg
subalign=2
subfont-text-scale=3
subwidth=70
The point here is that, there are two different sets of transcoding options in the same configuration file. Each set is referred to as a ” profile “. At the same time, if any one these option doesn’t work well, you can just comment it out using a ” # “. Alternatively, you can easily add in other options. When testing them, I’ll usually have one terminal running with mencoder.conf in a text editor, while the other is running mencoder.
Using Mencoder Profiles
Mencoder can be made to refer to a file other than mencoder.conf. However, you’ll save time by being able to copy and paste between different profiles. In addition, the ability to easily comment out anything that doesn’t work. Also, when you’re unsure of what profiles you have, and to check if the syntax is generally okay, just run:
mencoder -profile help
This will list your different “profiles” in mencoder.conf and mention any obvious errors.
Now to encode with Xvid using a fixed quantizer of 4 and have the new file in the same directory, just run:
mencoder -profile quant4 OLD.avi -o NEW.avi
Subtitles
To add in subtitles (in SRT format), just run:
mencoder -profile quant4 OLD.avi -sub OLD.srt -o NEW_subtitled.avi
Scaling
If the resolution is too high, scale it down to 720 pixels wide, and retain the original width/height aspect ratio.
[scale-quant4]
vf=scale
zoom=yes
xy=720
oac=copy=yes
ffourcc=XVID
ovc=xvid=yes
xvidencopts=fixed_quant=4:quant_type=mpeg
subalign=2
subfont-text-scale=3
subwidth=70
In Part 3, we’ll look at Xvid two pass encoding with Mencoder using a shell script.

Leave a Comment