#!/bin/sh

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

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

ffmpeg -i $input -f s16le -y $base.raw
sox -V -s -w -c2 -r24000 $base.raw -r48000 ${base}-slow.wav
ffmpeg -i $input -f yuv4mpegpipe -pix_fmt yuv411p -y /dev/stdout |
	yuvcorrect -T INTERLACED_BOTTOM_FIRST 2>/dev/null |
	yuvdeinterlace -d |
    yuvfps -s 30000:1001 -r 30000:1001 2>/dev/null |
	yuvcorrect -T PROGRESSIVE 2>/dev/null |
	ffmpeg -f yuv4mpegpipe -i /dev/stdin -i ${base}-slow.wav \
		-interlace 0 -vcodec dvvideo -acodec pcm_s16le \
		-y ${base}-slow.avi
