#!/bin/sh

help(){
	cat <<END
Usage: $0 [options] <filename>.[mpg]
Options:
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
*.mpg)
	input="$1"
	base=`echo $input | sed "s/\.mpg$//"` ;;
*)
	help ;;
esac

echo Slow motion $input to ${base}-slow.mpg video...

ffmpeg -i $input -f s16le -y $base.raw
sox -V -s -w -c2 -r24000 $base.raw -r48000 ${base}-slow.wav
toolame -b384 -s48 ${base}-slow.wav ${base}-slow.m2a
ffmpeg -i $input -f yuv4mpegpipe -pix_fmt yuv420p -y /dev/stdout |
	yuvcorrect -T INTERLACED_TOP_FIRST 2>/dev/null |
	yuvdeinterlace -d |
    yuvfps -s 30000:1001 -r 30000:1001 |
	yuvcorrect -T PROGRESSIVE 2>/dev/null |
    mpeg2enc --no-constraints -f3 -nn -a3 -Ktmpgenc -lh \
        -b24000 -V488 -r32 -G18 -D10 -q5 -s -o ${base}-slow.m2v
mplex -f3 ${base}-slow.m2v ${base}-slow.m2a -r28000 -b800 \
        -o ${base}-slow.mpg
