#!/bin/sh
# create video file
#

if [ $# -lt 2 ] ; then
	echo "Usage:"
	echo "$0 [-r] infile outfile"
	exit
fi

rot=0
if [ "$1" == "-r" ] ; then
	shift
	rot=1
fi

infile=$1
outfile=$2

# bump up frame rate to vcd std
mencoder -fps 20 -ofps 25 -nosound -ovc copy $infile -o out1.avi

echo "*** Starting lav2yuv ***"
if [ $rot == 1 ] ; then

	echo "*** Portrait scaling selected ***"

	lav2yuv +p out1.avi | \
	yuvscaler -M RATIO_1_1_4_7 -O SVCD -np | \
	mpeg2enc -f 4 -F 3 -o svcd.m2v

else
	
	echo "*** Normal scaling selected ***"

	lav2yuv +p out1.avi | \
	yuvscaler -O SVCD -np | \
	mpeg2enc -f 4 -F 3 -o svcd.m2v

fi


# sound
lav2wav -I +p $infile | mp2enc -V -o foo.mp2 

# make final file
mplex -f 4 svcd.m2v foo.mp2 -o $outfile

# Create the iso image and cue file
# videocd.bin
# videocd.cue
# NB can define multiple mpeg files here 
#echo "*** Starting vcdimager ***"
#vcdimager final.m2v

rm -f foo.mp2 out1.avi svcd.m2v

# burn it to disk
#cdrdao write --device 0,0,0 --driver generic-mmc videocd.cue

