Using HP DEC to record TV

The DE100C and DE200C have two PCI slots. On the DE200C, the two cards in PCI slots are - A modem card and a network card. Typically one would either use modem or network card to connect DEC to internet. So it is possible to free one PCI slot up for a TV tuner card. That is what I did. I removed the modem card and replaced it with an ATI TV Wonder card. I built driver modules for the tuner card. I then upgraded the RealPlayer on DEC to play RealVideo 9 codecs, installed Helix Producer 9.0.1, wrote a few scripts to control TV recording and set up cron job to record my favorite shows every week. To get reasonable performance, it was also necessary to upgrade the DEC hardware (CPU and memory).

Information about audio on TV tuner cards

TV tuner cards may have an analog audio output or they may have audio digitizer. TV tuner cards with analog audio only (ATI TV Wonder VE, I believe, is one such card) output TV sound on an analog output which needs to be connected to a sound card's line in to be able to record TV sound. TV tuners with audio digitizer present a digital audio interface to the kernel. Digital audio from such a card is available simply on another /dev/dsp device and you do not need to connect the analog audio output of the tuner card to sound card's line in. ATI TV Wonder has an audio digitizer.

Notes on performance

With 1 GHz celeron and 256 M RAM, recording TV at 320x240 and 1 Mbit/s bitrate keeps the CPU at 80%-95% busy. This means if you were to play music while recording TV, you are likely to notice hiccups in video or music. This also means it is not possible to watch a previously recorded TV program while recording another TV program. I have noticed Helix producer does fairly aggressive compression and produces fairly small files (450 MB for 1 hour of recording). This, I would expect, would impose fairly high load on CPU at the time of recording to get high compression rate. Another codec that does not compress as well but is easier on CPU might allow one to record a program while watching another program. I have tried recording at 640x480. It increased the CPU load to a point where I was getting very noticeable drop in frame rate with no noticeable improvement in video quality.

My setup

I am using the following hardware setup for TV recording:


Howto

WARNING: There is no support or warranty of any kind for the modification detailed on this web page. If you choose to make these modifications, you do so at your own risk. If you are not comfortable with hardware upgrades and Linux software upgrades, do not proceed with these modifications.

To record TV on DEC, you need the following hardware:

1. A faster CPU, 1 GHz Celeron or Pentium 3
2. More memory - 1 256 M stick for DE200C and 2 256 M sticks for DE100C. DEC uses PC100 memory.
3. A TV tuner card supported by Video4Linux.
4. Bigger hard disk if you are going to record lot of TV. Each hour of recording takes up around 450 MB of disk space.

Follow these steps to start recording TV:

1. Unlock DEC
2. Upgrade CPU and memory
3. Upgrade hard disk, if you would like.
4. Install the TV tuner card following the hardware installation instructions that came with the card. Power up the DEC and make sure everything still works.
5. Verify the TV tuner card is detected by Linux - issue the command 'lspci' and make sure TV tuner card is listed.
6. Install xawtv
7. Install TV tuner driver modules
8. Update RealPlayer
9. Install Helix Producer
10. Set up to load TV tuner modules automatically on reboot.
11. Install script to set up recording

Unlock DEC

Follow the instructions here.


Upgrade CPU and memory

Follow the instructions here.


Upgrade hard disk

Follow the instructions here. Most of the instructions on upgrading hard disk relate to unlocking DEC, but you have done that already :-)


Install xawtv

1. Download xawtv for DEC from here. Copy this file to DEC.
2. Install xawtv as follows:
3. Create the /etc/X11/xawtvrc file appropriate for your TV feed. You can use my xawtvrc file as starting point.

xawtv package includes v4lctl that allows you to control the TV tuner card. One interesting bug I have found in v4lctl is if you were to try to tune the TV card to a channel under channel 19 and you use the channel number as option to "v4lctl setstation", v4lctl picks the wrong frequency for the channel. For example when I tell it to tune channel 9, it tunes channel 19, when I tell it to tune channel 3, it tunes channel 23, etc. A workaround is to use the channel names instead that you have defined in /etc/X11/xawtvrc.


Install driver modules

1. Download driver modules from here. Copy the file to DEC.
2. Install the driver modules as follows:
3. run 'depmod -a'.
4. Load the appropriate driver for your tuner card. For ATI TV wonder and most other BT8xx chipset based cards, it will be bttv . Load the "tuner" module as well if it is not autoloaded. Tuner on ATI TV Wonder card is not detected properly which will result in channels being off by one and picture being grainy and almost black and white. You need to tell bttv module the tuner type, for example "modprobe bttv tuner=2".
5. If you have another machine running X-windows, check if xawtv can see the card by issuing following commands:
# export DISPLAY=`hostname`:0
# xawtv -hwscan

You should get an output similar (not identical) to:

This is xawtv-3.81, running on Linux/i686 (2.4.7-17emso)
looking for available devices
/dev/video0: OK                         [ -device /dev/video0 ]
    type : v4l
    name : BT878(Hauppauge new (bt878))
    flags: overlay capture tuner

6. Test the driver by running xawtv as follows:
At this point you should see the TV picture on DEC monitor (TV screen if your DEC is connected to a TV).


Update Real player

1. Download RealVideo 9 codecs from http://docs.real.com/docs/playerpatch/unix/rv9_libc6_i386_cs2.tgz. Copy this file to DEC.
2. Extract files from the downloaded tar archive (tar xzvf rv9_libc6_i386_cs2.tgz).
3. Read the "readme.txt" file for upgrade instructions. Essentially you need to copy two files as follows:

Install Helix producer 

1. Download from http://forms.real.com/rnforms/products/tools/producerbasic/index.html.
2. Copy the downloaded file to DEc and make sure it is executable (use chmod to make it executable if it is not).
3. Run the downloaded file and follow instructions. I would suggest installing helix producer in /usr/local. Also let the install software make links for helix producer in directories that are in the normal PATH.
4. If you are using a TV tuner card with audio digitizer, load the appropriate audio module. For ATI TV Wonder card, it would be btaudio.
5. Create a temporary directory to record TV programs into (mkdir /content/tmp).
6. Test if helix producer works by issuing following command:

producer -bl -ac /dev/dsp1 -vc /dev/video0 -vp 0 -d 0:0:3:0 -cs 320x240 -o /tmp/tst.rmvb -ad 1M -am music -vm normal -arq fast -t "Testing TV tuner" -a "TV"

Use the appropriate /dev/dsp device with -ac option. /dev/dsp1 would be the right device for TV tuner cards with audio digitizer. Helix producer should start recording currently tuned TV channel:

Helix(TM) Producer Basic 9.0.1 from RealNetworks(R). Build number: 9.0.1.250
Warning: Ignoring enableTwoPass for live encoding                             
Info: Starting encode 
Encoding: 0:45.4/3:00.0 (25%) Errors: 0 Warnings: 1 [------    ]-11dB


Numbers after "Encoding:" are time recorded/time to be recorded. The dB value reported by is the sound level from the audio input you specified. Time recorded so far should count up to 3:00 and recording should stop. Check the size of file /tmp/tst.rmvb, it should be non-zero, around 22 MB.

To view the recording and make sure it worked, move the recorded file to /content/imported/tmp:
# mv /tmp/tst.rmvb /content/imported/tmp/tst.rm
Stop playing music if you were, Go to the main menu on DEC and leave it there for a few minutes. This will give DEC a chance to import the video file. After a few minutes, go to the menu "Library-->music-->Artists-->TV". You should see the video titled "Testing TV tuner". Play this recording and make sure video plays correctly. If it does you are in business.


Set up driver modules to load automatically

Once you have determined the right modules to load and determined they work, it is time to set up so that these driver modules are loaded automatically upon reboot. First of all, if you needed to provide a tuner type when loading TV card driver, it would be a good idea to add that option to /etc/modules.conf. Here is what I added to /etc/modules.conf:

alias char-major-81 bttv
options bttv tuner=2


The driver for my TV card is bttv.

Right way to autoload modules is to add them to /etc/modules, but when I tried that on DEC, the modules wouldn't load reliably. So I implemented a workaround. I wrote an init script /etc/rc.d/init.d/tv which loads the right modules for my card. I then set up links in runlevel 5 to start this script. Here are the steps:

1. Download the init script /etc/rc.d/init.d/tv and install under /etc/rc.d/init.d. Make sure it is executable.
2. Establish symlinks as follows:
# cd /etc/rc.d/rc5.d
# ln -s S99tv ../init.d/tv
# cd /etc/rc.d/rcb5.d
# ln -s S99tv ../init.d/tv



Script to set up TV recording

1. Download this script and copy it to /usr/local/bin. Make sure the script is executable.
2. Edit this script and change the second line starting with "KNOWN_CH=" to match the channel names you defined in /etc/X11/xawtvrc. This is a workaround for the bug I mentioned in "Install xawtv" section.

Notes: There are couple of things worth pointing out in this script. You will notice "v4lctl setstation" command being issued twice. There were occasions when I noticed issuing a single command did not change station reliably. So I do this twice. Secondly, the script disables screensaver before starting recording and re-enables it when it video recording is done. This is because screensaver tends to take up 7%-10% of CPU when it is running. There are many combinations possible for parameters to producer that affect CPU load, recording quality and file sizes. I have not played with all combinations. The combination in script is the best compromise I have found so far between CPU load and video quality. Feel free to experiment here and let me know if you find a better performing combination.

3. When you want to schedule a recording, simply run "vcr" and answer the questions. After the program has been recorded, you will find it under "Library-->music-->Artists-->TV".

You may notice in this script, I am recording to a file /content/tmp/<file>.rmvb and then I move it later to /content/imported/tmp/<file>.rm instead of recording directly to /content/imported/tmp/<file>.rm. The reason for that is Helix producer insists upon .rmvb extension for the file it produces. DEC does not know about .rmvb files (I tried adding rmvb to the list of known extensions in /opt/odin/dec/odin/Odin_1_0 but that did not help). When I recorded directly to /content/imported/tmp/<file>.rmvb, DEC would delete the file while it was still being recorded. This was a simple workaround.

This script will schedule up one time recording. For recurring recordings, I use cron. I have written individual scripts for each TV program I wish to record (these scripts are almost identical to the ones generated by vcr script). These scripts are run by cron to record the program. Here is an example. One problem I found with using cron was that the DEC maintenance scripts that run every night reset root's crontab. So I could not set up cron jobs for the root user to record recurring TV programs. There is probably a way to work around the crontab being reset problem. I simply created another user (which I had already done since I have been working on getting mythtv working on DEC and I had created the user "mythtv" already to do that. I have mythtv almost working. I just have o resolve some X-server issues, but that is another story). You can use adduser to do that. If you create another user to schedule cron jobs for recording recurring TV shows, you will also need to make sure /dev/video0 and /dev/dsp*, /content/tmp and /content/imported/tmp have the permission 666.