#!/bin/bash

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

ffmpeg -i $base.264 -f yuv4mpegpipe -pix_fmt yuv420p -y /dev/stdout |
    yuvcorrect -T INTERLACED_TOP_FIRST |
    yuvdeinterlace -d |
    yuvcorrect -T PROGRESSIVE |
    yuvscaler -M BICUBIC -O SIZE_720x480 |
    yuvfps -s 60000:1001 -r 60000:1001 |
    y4minterlace -ib |
    yuvcorrect -T INTERLACED_BOTTOM_FIRST |
    mpeg2enc -M0 -nn -a3 -f8 -G18 -b7000 -V230 -q9 -o $base.m2v
