#!/bin/bash encoder="/home/xero/misc/scripts/timed-copy" savedir="/home/xero/tmp/video" statfile="/home/xero/misc/scripts/.tvstat" channel="32" timer="29.9" input=0 card=0 sat=72 cont=68 bright=134 #brighter #sat="72" #cont="72" #bright="152" #default #sat="64" #cont="64" #bright="128" #kouga #sat="90" #cont="64" #bright="120" while getopts c:o:t:plkdsqh name do case $name in c) channel="$OPTARG";; o) filename="$OPTARG";; t) timer="$OPTARG";; p) play=1;; l) listrec=1;; k) kill=1;; d) card=1;input=1;; s) card=1;; q) quiet=1;; h|?) help=1;; esac done device="/dev/video$card" if [ $help ]; then echo -e "Usage: `basename $0` [OPTIONS] [-l|-k|-p|-o FILE]" echo -e " -c channel 1-125" echo -e " -o output file name" echo -e " -t record duration <[[hh:]mm:]ss[.ms]|size[b|kb|mb]>" echo -e " -p play instead of record" echo -e " -l list currently recording" echo -e " -k kill recording" echo -e " -s use second card" echo -e " -d use dvr on second card" echo -e " -q quiet recording output" echo -e " -h display this help and exit" exit 0 elif [ $listrec ]; then if [ -e $statfile.0 -o -e $statfile.1 ]; then cat $statfile.* exit $? fi echo "No instances found" exit 1 elif [ $kill ]; then if [ -e $statfile.$card ]; then pid=`tail -n1 $statfile.$card` kill -TERM `ps -ef| awk '$3 == '$pid' { print $2 }'` exit $? fi echo "No instance found to kill" exit 1 elif [ $play ]; then v4l2-ctl -d$card -csaturation=$sat,contrast=$cont,brightness=$bright \ -ctemporal_filter_mode=1,spatial_filter_mode=1,median_filter_type=3 -i$input ivtv-tune -d$device -c$channel mplayer $device -vf crop=698:472:12:2,pp=lb,dsize=4/3 -framedrop -nocache exit $? elif [ ! $filename ]; then echo "Must specify filename. See -h:" $0 -h exit 1 fi date=`date +%b%d-%H.%M` filename="$filename-$date" while [ -e "$savedir/$filename.mpg" ]; do filename="${filename%-$date}-1-$date" done if fuser $device >/dev/null 2>&1; then echo -e "Subject: TV Recording Error\n$filename\nInstance found, killing\n`fuser -vk15 $device >/dev/stdout 2>&1`"|/usr/lib/sendmail xero@xeron.cc sleep 5 if fuser $device >/dev/null 2>&1; then echo -e "Subject: TV Recording Error\n$filename\nInstance didn't die, forcing\n`fuser -vk $device >/dev/stdout 2>&1`"|/usr/lib/sendmail xero@xeron.cc sleep 2 fi fi record() { #min=`echo $timer|egrep -o .*: || echo 0:` #timer=$(( ${min/:/} * 60 + ${timer/$min/} )) v4l2-ctl -d$card -csaturation=$sat,contrast=$cont,brightness=$bright \ -ctemporal_filter_mode=1,spatial_filter_mode=1,median_filter_type=3 -i$input ivtv-tune -d$device -c $channel $encoder -v -m $timer < $device > $savedir/$filename.mpg #cat $device > $savedir/$filename.mpg < /dev/tty & #recpid=$! #sleep $timer #kill $recpid } echo -e "Recording ${filename%-$date} on channel $channel at $date for $timer on card $card\n$$" > $statfile.$card if [ $quiet ]; then record >/dev/null 2>&1 else record fi rm -f $statfile.$card