Building a PVR project

Discuss Applications
User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Sat Mar 31, 2007 2:44 pm

I asked a question the other day (in the wrong section of these forums) about how to stream audio from the FM tuner in my Hauppauge PVR-500 card over http:

http://forum.videolan.org/viewtopic.php?t=34320

There is a program that I enjoy listening to on the FM radio but I only can catch a little bit of it on my drive to work in the morning. So now I have a cron job set up to record it every day and another script I can execute to stream the file over http using VLC if I should want to listen to the show over a stream as it is recording, or listen to a previous show I may have missed.

Basically here is the script to record the audio and save it in a low quality ogg file:

$ cat /usr/local/bin/radio-record

Code: Select all

#!/bin/bash

if [ $# -ne 3 ]; then
   echo "Syntax: radio-record <freq> <prefix> <seconds>"
   echo "Example: radio-record 94.7 \"Bob and Tom\" 14400"
   echo "Example: radio-record fox Glover 7200"
   exit
fi

FREQ=$1;
PREFIX=$2;
DURATION=$3;

DATE="`date +%m/%d/%y`"
FULLDATE="`date`"
DATETIME="`date +%Y%m%d-%H%M`"
YEAR="`date +%Y`"

if [ "${FREQ}" = "kshe" ]; then
   FREQ="94.7"
fi
if [ "${FREQ}" = "fox" ]; then
   FREQ="97.1"
fi
 
FILE="/backup/radio/${PREFIX}_${DATETIME}.ogg"
echo "Recording to ${FILE}"
cat /dev/video25 | sox -t raw -r 48000 -w -s -c2 /dev/stdin -t wav - | oggenc --resample 11025 - -b 8 -q 0 -a "${PREFIX}" -G "Other" -t "${PREFIX} - ${DATE}" -c "=${FREQ} FM on ${FULLDATE}" -o "${FILE}" &
PID=$!
ivtv-radio -d /dev/radio1 -i /dev/video25 -f ${FREQ} -c "sleep ${DURATION}"
kill ${PID}
The show is 4 hours long every day and I want to keep the file size down so I have reduced the bitrate and resampled it to 11k. This only takes up a little over 10MB/hr which. The recording/encoding/vlc streaming processes only consume around 10% of the CPU on the old 800Mhz PC acting as my MythTV machine which can also happily record 3 TV programs at the same time (via 1 PVR-350 and 1 PVR-500). Here is the cron job to record Bob and Tom for 4 hours starting at 5:00am:

Code: Select all

0 5 * * 1-5 /usr/local/bin/radio-record 94.7 "Bob and Tom" 14400 > /tmp/radio-record.log
Now I can stream that file with VLC while it is recording, or stream any of the archived files with this script:

$ cat /usr/local/bin/stream-oggfile

Code: Select all

#!/bin/bash

if [ $# -ne 1 ]; then
   echo "Syntax: stream-oggfile <filename>"
   exit
fi

/usr/bin/vlc "$1"  -I http --http-host=:8002 ":sout=#standard{access=http{user=$HTTP_USER,pwd=$HTTP_PWD,mime=application/ogg},mux=ogg,url=:8001}"
Then I just point my Firefox browser (or vlc client) to my myth box http://myth:8001/ to listen to the stream and I can control the stream with http://myth:8002/.

Screenshot:
http://voidmain.is-a-geek.net/i/vlc.png

I set up an ssh tunnel from work into my Myth box so I can listen to the parts of the show I missed on the drive in. :)

Maybe this will help someone else. Or maybe someone will give me some advice on a much easier/better way to do what I am doing.

Post Reply