#!/bin/bash -x
# 1: channel
# 2: time in seconds
# 3: recording file

echo "Chan=$1  Dur=$2  Fil=$3"

kill_it()
{
  echo "Caught SIGINT in record.sh, record aborted."
  kill $CATPID
  exit
}
trap 'kill_it' INT TERM

if [ $# == 0 ] || [ "$1" = "-h" ] ; then
	echo "Usage: $0 channel duration file"
	exit 1
fi


#configuration freq norm audio video
/usr/share/freevo/station2freq.pl $1 >& /dev/null

#enregistrement
cat /dev/video1 > $3 &
CATPID=$!
echo "Recording started, Process ID is $CATPID"

ps -ef | grep $CATPID
echo "waiting..."
sleep $2
kill $CATPID
echo "Recording complete, process $CATPID terminated"
