#!/bin/sh
help(){
    echo "Usage: $0 <filename.[rm]>"
    exit 0
}
if test "$#" != "1"
then
	help
	exit
fi
case $1 in
*.rm)
    input="$1"
    base=`echo $input | sed "s/\.rm$//"` ;;
*)
    help ;;
esac
echo Encoding $input to $base-tmp.avi....
mencoder $input \
	-ovc lavc -lavcopts vcodec=ljpeg -oac pcm -o $base-tmp.avi
avifix -i $base-tmp.avi -F MJPG
echo Encoding $base-tmp.avi to $base.avi....
sleep 1
sed "s/^interlaced.*$/interlaced = 0/;
	s/^topfieldfirst.*$/topfieldfirst = 0/" \
	< /usr/local/lib/transcode/xvid4.cfg \
	> xvid4.cfg
transcode -i $base-tmp.avi -x ffmpeg --encode_fields p \
	--export_asr 3 --export_par 1 -E 32000,16,1 \
	-R 0 -y xvid4 -b 48 -w 210 -Z 320x320 -Y 0,0,80,0 -o $base.avi
rm $base-tmp.avi
