#!/bin/bash

# use with this VCR_CMD:
# VCR_CMD = ('/usr/local/freevo_data/tvrecord/tvrecord %(channel)s %(seconds)s "%(filename)s"')

CHAN=$1
TIME=$2
NAME=$3

# Hieght and width of the recording
WIDTH=496
HEIGHT=368

# location of programs we use
MENCODER=/usr/bin/mencoder
SMIXER=/usr/bin/smixer

# DIR is the directory you put in local_conf.py for TV_RECORD_DIR
DIR=/usr/local/freevo_data/RecordedTV
# DIR where I put the script and the two helper files for smixer
SCRIPTDIR=/usr/local/freevo_data/tvrecord
# where freevo lives. I often cd here to put the reorcing logs in place
FREEVOHOME=/usr/local/freevo

# suck up as much of the cpu as we can. 
# Only works as root. remove if not recording as root
NICE="nice -n -20"

# now building our mencoder options string
AUDIO="-oac mp3lame -lameopts cbr:br=128"
VIDEO="-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1400"
DSP="adevice=/dev/dsp:forceaudio:forcechan=1"
TV="-tv on:driver=v4l:width=$WIDTH:height=$HEIGHT:input=0:device=/dev/v4l/video0:norm=NTSC:chanlist=us-cable:channel=$CHAN:$DSP"

# real magic starts here
cd $FREEVOHOME
$SMIXER -s $SCRIPTDIR/unmutelineinandrec.txt
$NICE $MENCODER $TV $VIDEO $AUDIO -endpos $TIME -o "$NAME.avi" tv://$CHAN
$SMIXER -s $SCRIPTDIR/mutelinein.txt

