#!/bin/sh
#
# recode audio in mpg file
#
def_format=8
def_abitrate=224

help(){
	cat <<END
Usage: $0 [options] <filename.[mpg]>
Option:
    -a n      Set the audio bitrate                 ($def_abitrate)
    -f n      Output type 1=vcd, 4=svcd, 8=dvd      ($def_format)
    -h        Print this help message
END
	exit 0
}

format=$def_format
abitrate=$def_abitrate

while getopts a:f:h name "$@"
do
    case $name in
a)
	abitrate=$OPTARG ;;
f)
    format=$OPTARG ;;
*)
    help ;;
    esac
done
let shiftind=$OPTIND-1
shift $shiftind

if test "$#" != "1"
then
	help
	exit
fi
case $1 in
*.mpg)
    input="$1"
    base=`echo $input | sed "s/\.mpg$//"` ;;
*)
    help ;;
esac

case $format
in
8)
	tflags="-target dvd" ;;
4)
	tflags="-target svcd" ;;
*)
	tflags="-target vcd" ;;
esac

echo Recoding audio for $input....
sleep 1
echo ffmpeg -i $input -vcodec copy $tflags -ab 224 -y $base-re.mpg
#ffmpeg -i $input -vcodec copy $tflags -ab 224 -y $base-re.mpg
#ffmpeg -i $input -vcodec copy -acodec ac3 $tflags -ab 224 -y $base-re.mpg
ffmpeg -i $input -vcodec copy -acodec copy $tflags -y $base-re.mpg
