The reason to use a separate work directory here is that xvid4 creates a file called "divx4.log" in the current working directory, so otherwise it would become overwritten if multiple instances of this script were to run:
Set the resize parameter. Quite a confusing parameter indeed. I won't try to explain it here, even if I really could, instead I'll just give the two most commonly used settings, without taking account of how slow these settings actually cause transcode to run.
If the source VOB contains widescreen aspect ratio (also known as letterbox, because of the black bands along the top and bottom of the picture), set RESIZE as follows. Actually any aspect ratio that's not 4:3 seems to work well with this setting:
export RESIZE="-B 12,10,8"
If the source VOB contains fullscreen (4:3) aspect ratio, set RESIZE as follows (this can be very slow):
export RESIZE="-g 720x480 -Z 640x480"
Use a bitrate ranging from as low as 500 to as high as 2500, depending on how large a screen you intend to playback the resulting xvid:
export BITRATE="-w 1500,250,100"
If you see thin horizontal lines on fast motion, you need to deinterlace:
export DEINTERLACE="-I 3"
If you want to keep the original AC3 soundtrack rather than encode it to mp3, e.g. if you are using an external "receiver", use this:
export AC3PASSTHRU="-A -N 0x2000"
Invoke the first pass of transcode, this is to allow the xvid encoder to figure out the best amount of compression to use, depending on the content of the source. The use of the "-M 2" flag can help to keep the audio in sync with the video:
transcode -i $IN -M 2 $BITRATE $DEINTERLACE -a 0 -b 128,0,0 $AC3PASSTHRU -f 25 $RESIZE -R 1 -x vob,null -o /dev/null -y xvid4
Invoke the second transcode pass, this reads the "divx4.log" file:
transcode -i $IN -M 2 $BITRATE $DEINTERLACE -a 0 -b 128,0,0 $AC3PASSTHRU -f 25 $RESIZE -R 2 -x vob -o $OUT -y xvid4