#!/bin/sh
# Convert a MythTV saved recording into a video file.

base=`basename $1 .nuv`

start_tc () {
	rm -f audout vidout
	nice mythtranscode \
		`echo $base | perl -pe 's,^(\d+)_(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)_(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d),--chanid $1 --starttime $2-$3-$4T$5:$6:$7,'` \
		--profile autodetect \
		--fifodir . \
		--honorcutlist &
	while [ ! -e audout ] || [ ! -e vidout ] ; do
		sleep 1
	done
}

do_encode () {
	start_tc
	nice mencoder \
		-audiofile audout \
		-audio-demuxer 20 \
		-rawaudio rate=44100 \
		-rawvideo on:w=480:h=576:fps=25 \
		-vf scale=480:360 \
		-ovc lavc \
		-lavcopts vcodec=mpeg4:vhq:vbitrate=1200:vpass=$1 \
		-oac mp3lame \
		-lameopts mode=0:preset=extreme \
		-o "$base.avi" \
		vidout
	wait
}

rm -f divx2pass.log
do_encode 1
do_encode 2

