131
Chapter 7, How to Build a Digital Video Recorder
You will probably want a slim case for the parts as well. A complete PC may
even be available from eBay or a local computer shop with all of these parts
already installed. The HP desktop PC case and system pictured in Figure 7-1
was upgraded with a new hard drive and worked well for this project.
Put the PC together and test it out with a standard VGA monitor before pro-
ceeding. You can install any operating system you like for testing because it
will be replaced later.
Software Setup Instructions
The first thing you need to do is install a Mandrake Linux Version 8.2 pack-
age on your computer. Next, you will install a number of Video4Linux driv-
ers and software packages. Finally, you will test out your system.
1. Install Mandrake Linux Version 8.2
Download or purchase a copy of Mandrake Linux 8.2 and install it on the
PC you’ve constructed. The software should recognize all of the hardware.
You will need to use a standard monitor when installing the software
because it requires at least 800 by 600 resolution.
Figure 7-1: Home-built PVR in place
Which Version of
Linux?
There are a number of Linux pack-
ages available today that will prob-
ably work with this project. Mandrake
8.2 was used and tested because it
included XAWTV (X Athena Widget
set for TV) and drivers for most video
capture cards. If your Linux package
does not include drivers for your
video capture card and the XAWTV
video record/playback utilities, you
will need to obtain and load them
yourself.
Software Setup Instructions
ch07_video.indd 131
1/21/2002 12:52:49 PM
132
Part II: Advanced Hacks, Tools, and Techniques
2. Configure the system
1. Start by creating a login account. A login of tv with no password will
work well.
2. Create a directory to store your recorded programs. A directory called
“shows” should work.
3. Add these lines to the /etc/modules.conf file:
pre-install videodev modprobe -k tuner type=2
options bttv gbuffers=2 card=16 radio=1 fieldnr=1
4. Create a script that triggers video recording. Below is an example script
called rec that you can locate in /home/tv:
#!/bin/bash
if test -z "$2"; then echo "usage: channel lengthoftime"; exit; fi
f=shows/'date +%y%m%d-%a-%H_%M'
echo $f >> /tmp/TV_rec.err
echo Recording channel $1 ($2) at 'date'" >> /tmp/TV_rec.status
killall -9 xine 2>> /tmp/TV_rec.err
killall -9 mplayer 2>> /tmp/TV_rec.err
killall -9 xawtv 2>> /tmp/TV_rec.err
v4lctl setchannel $1 2>> /tmp/TV_rec.err
v4lctl volume 100 2>> /tmp/TV_rec.err
mencoder -tv on:driver=v4l:device=/dev/video0:norm=NTSC:
width=320:height=240 -oac copy -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=800 -vop pp=lb -endpos $2 -o $f.avi 2> /dev/
null > /dev/null
echo " Ended recording channel $1 at 'date'" >> /tmp/TV_
rec.status
If you wish the files to be VCD-compatible, remove the mencoder line
and replace it with:
streamer -n ntsc -q -t $2 -s 320x240 -r 20 -o $f.avi -f jpeg -j
86 -F stereo 2>> tmp/TV_rec.err
The mencoder format allows a very high frame rate (up to 27 fps on the
system tested).
To operate the script, pass it the following arguments: the channel
number, and a number of minutes and seconds to record. It will then
record a file in the format “YYMMDD-day-HH_MM.avi” (e.g.,
021008-
Tue-19_00.avi
) in the shows subdirectory.
This script does a lot of things that arent really crucial. All the output is
redirected to a log file for debugging purposes. It also writes to a status
file before and after the recording.
If you are running other programs and your Linux PVR is not a dedi-
cated machine, the
killall -9 command is a bit harsh. You can replace
this with a simple
kill command instead or add a series of escalating
termination commands to the script.
What Is a VCD?
VCD stands for video CD. VCDs use a
file format that can be burned onto
a standard compact disc and played
back on most DVD players. For details
on how to go about this, check out
http://sourceforge.net/projects/vcd-
master/.
Card ID
If you have chosen to use a different
capture card, the “card=16” in this
code should be changed to the card
you are using. Check this web site for
card ID details: http://sdb.suse.de/en/
sdb/html/cg_wintv.html.
Software Setup Instructions
ch07_video.indd 132
1/21/2002 12:52:49 PM

Get Hardware Hacking Projects for Geeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.