#!/bin/bash
help(){
    cat <<END
Usage: $0 [options] <filename.[png]>
Options:
    -h        Print this help message
END
    exit 0
}

while getopts h name "$@"
do
    case $name in
*)
    help ;;
    esac
done
let shiftind=$OPTIND-1
shift $shiftind

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

echo Making menu from $input to $base.mpg

cat <<EOF >$base.xml
<subpictures>
 <stream>
   <spu
       force="yes"
       start="00:00:00.00"
       select="${base}h.png"
       highlight="${base}h.png"
       autooutline="infer"
       outlinewidth="4"
       autoorder="rows">
 </spu>
 </stream>
</subpictures>
EOF

pngtopnm $base.png | 
        ppmtoy4m -n1 -Ip -A10:11 -S420mpeg2 | 
        mpeg2enc -f8 -nn -o$base.m2v

dd if=/dev/zero bs=4 count=1920 |
        toolame -b128 -s48 /dev/stdin $base.mp2

mplex -f8 -o /dev/stdout $base.m2v $base.mp2 | 
        spumux -v 2 $base.xml >$base.mpg

