Homemade Tivo

Overview

I used a TV card in an old Linux box to create my own Tivo. There are a lot nice applications that try to accomplish this, but many of them are difficult to install and use. Most of them required more speed than the K6-2/500 system could handle.

Approach

I just used existing command-line tools to get the job done. My card worked great with the streamer program. I configured the TV card to recognize the channels in my area. Then, I set it to go to my VCR channel by default when opening. Finally, I wrote a script, capture.sh, to instantly start recording on given station for a duration of time to a given filename.

capture.sh:

#Parameters:
 
#$1=station (as stored in ~/.xawtv)
#$2=duration
#$3=filename
 
#turn off xawtv
killall xawtv
 
#turn off audio out
aumix -v 0 q
 
#Tune into the channel.
v4lctl setstation $1
 
#capture the channel.
streamer -t $2 -s 352x240 -r 20 -o $3 -f mjpeg -F mono16 -R 22100 -q 25
 
#turn on audio out
aumix -v 75 q
 
#turn on xawtv in fullscreen
xawtv -display power:0.0 -f &

Typically, this computer is just used as a TV by always running the xawtv process. So, the script starts by killing the xawtv process to get access to the TV card. Then, it turns off the audio so I don't hear the recording. Then, it sets the station and starts recording. Finally, it turns the audio back on and opens the TV on the video screen by running xawtv.

Scheduling

To schedule a program, I use the at command. at simply runs a script at a given time. Since the capture.sh script above requires parameters, I wrote another script to schedule a program, schedule.sh. It takes an extra parameter for the time of the recording.

schedule.sh:

#options
#$1 channel
#$2 time
#$3 length
#$4 name
 
#Create the script to record the program
echo "./capture.sh $1 $3 /usr/local/power/vcr/$4.avi 2> /dev/null" > temp.sh
 
#Schedule it.
at -f temp.sh $2

So, to schedule a program on Channel 17 at noon for 1 hour called news, the command would be:

./schedule.sh 17 12p 60:00 program

Viewing

To make this solution complete, I store all TV programs on a NFS-shared directory. I've found that NFS gives much better performance than SAMBA. I can watch the stored TV programs on my laptop using an 11Mbps, 802.11b wireless connection. It comes in quite smooth using mplayer to view the captured file.

Compression

The files themselves are quite large, about 2GB/hour. With faster systems, it is possible to compress the video on the fly. However, with my little K6-2/500, I must compress the video files after the fact.

In order to compress an avi to an mpg, the avi must be within a standard frame rate. To get this rate, the capture script must be modified so the rate of the video is 24 frames per second. Change the line:

streamer -t $2 -s 352x240 -r 20 -o $3 -f mjpeg -F mono16 -R 22100 -q 25

to

streamer -t $2 -s 352x240 -r 24 -o $3 -f mjpeg -F mono16 -R 22100 -q 25

Then, use a script that I discovered when typing streamer -h. I call it avi2mpg.sh:

lav2wav +p $1.avi | mp2enc -o $1.mp2
lav2yuv +p $1.avi | mpeg2enc -o $1.m1v
mplex $1.mp2 $1.m1v -o $1.mpg

It takes a LONG time to compress a video with my system, about six times the length of the original video. During this time, the system is too bogged down to do much else, including capturing more video. So, I very rarely will use the script, but it does work. I find it better to use a 20 frames/sec rate instead to save hard drive space. Then, I just delete the programs immediately after viewing them.

Conclusion

It's not necessary to have a fast computer to have a Tivo in Linux. It's just a matter of using the right tools and having enough hard drive space available.