|
|
...making Linux just a little more fun! Digital TelevisionBy Peter Knaggs
Sorry to start off with such a bunch of alphabet soup, but it seems unavoidable, when trying to make sense of the subject of digital television. In the USA, terrestrial digital video broadcasts are transmitted in 8VSB-modulated ATSC-encoded MPEG-2 transport streams, containing high-definition content in progressive 720p (1280x720) and interlaced 1080i (1920x1080) formats. I'm still not even sure what the official name for this stuff is, so let's just call it HDTV. So How Can I Get This HDTV Stuff?There are two aspects to consider. The first is your antenna, and the second is the card to use in your Linux box. It may strike you as unusual, in these modern times, for me to suggest that the most economical way of upgrading the quality of your TV reception is not to subscribe to some new-fangled "digital cable", but rather to use an old-fashioned antenna, the kind you probably used to have up on the roof of the house when you were a kid. Antenna ConsiderationsYou can check what sort of antenna you're likely to need by going to Antenna Web, and also by looking up the particular stations you find there in the FCC database, to get an idea of their transmission power (ERP) and height above the terrain (HAAT). The FCC provide the antenna locations, in terms of latitude and longitude. You can find the entire table of stations in this directory, in the following files: table1.pdf table2.pdf table2a.pdf. For example, doing a search for Zip code CA94065, you'll find plenty of stations that can be received with nothing more than a regular indoor TV antenna (i.e., a plain piece of wire, nothing special). Since the digital TV transmitters tend to have been installed on the same towers used by analog TV transmitters, apparently a fairly good indicator of whether or not you'll be able to receive digital TV is to see what sort of analog TV reception you currently get with just a basic VHF antenna. If you can get even a few "snowy" channels with analog TV, your chances are good for digital TV. The PC CardAs of March 2005, there seem to be only three HDTV cards for use in Linux PCs, the pcHDTV, the Air2PC card, and the FusionHDTV card. I've tried the pcHDTV card. Initial ResultsBack in March 2005, to get going and to see what the pcHDTV card was capable of, I installed one pcHDTV HD-3000 card into a Dell Dimension XPS, and one into an ASUS Barebone. I installed the KnoppMyth distribution from KnoppMythR5A12, then built and installed the xine-hd sources provided by pcHDTV on their accompanying CD, and followed the advice in the very amazing, accompanying three-page printed handout to use the command: dtvscan /dev/dtv > $HOME/.xine/channels.atsc This created a file with the following contents (using only a wire antenna): KNTV-HD: :11.1 :12: 4:0 NBC Wea: :11.2 :12: 5:0 KNTV-HD: :11.1 :12: 4:0 NBC Wea: :11.2 :12: 5:0 KGO-DT : : 7.1 :24: 3:0 KGO-DT : : 7.2 :24: 4:0 KTSF D1: :26.1 :27: 2:0 KTSF D2: :26.2 :27: 3:0 KPIX DT: : 5.1 :29: 1:0 KQED-HD: : 9.1 :30: 3:0 ENCORE : : 9.2 :30: 4:0 KMTP-DT: :32.1 :33: 3:0 KCNS : :38.1 :39: 3:0 KCSM : :43.1 :43: 2:0 JazzTV : :43.2 :43: 3:0 KBHK-DT: :44.1 :45: 1:0 KSTS-DT: :48.1 :49: 3:0 KNTV-DT: :48.2 :49: 4:0 KTEH-DT: :54.1 :50: 1:0 KDTV-DT: :14.1 :51: 1:0 KICU-HD: :36.1 :52: 3:0 : :56.1 :56: 2:1 KRON-SD: : 4.1 :57: 3:0 KRON-HD: : 4.2 :57: 4:0
After that, to view HDTV channels, it was only a matter of
configuring xine dtv:// Recording is done by selecting the number from the second numeric column corresponding to the channel. For example, to record from KQED-HD, use the command: getatsc /dev/dtv0 30 > filename.mpg
To play back such recordings, just use either
xine-hd (which is a version of xine patched by pcHDTV for viewing HDTV
streams) or mplayer. It seems that, oftentimes, multiple program
streams are recorded within the MPEG transport, due to the
transmitting station making use of xine -C 30.3 filename.mpg mplayer -tsprog 3 filename.mpg So what's this I hear about surround sound?Some of the digital channels, for example, KTVUHD (channel 56, program stream 3) and KPIX (channel 29, program stream 1), transmit audio using an A/52 5.1 channel 48000 Hz stream. Essentially, this means that the audio stream contains five regular audio channels (center, front left, front right, side left, and side right) plus one low-frequency effects channel (subwoofer). It's the same sort of audio stream commonly used for DVD movies. If you have an external audio decoder (for example, I tried this using a Pioneer VSX-D711 receiver), and your sound card supports AC3 pass-through, then you can simply connect up the digital output from the sound card to the digital input of the receiver, and let the receiver do all the work of decoding the audio.
To select AC3 pass-through with
To get mplayer -ao alsa -ac hwac3 -tsprog 3 filename.mpg Is there a command-line tool for scheduling recordings?Inkling's pchdtvr is probably what you've been looking for. It's an amazing console application.
Here's a screen shot of
Because full ATSC streams eat up large amounts of disk space,
you'll be happy to see that Inkling's latest release, pchdtvr 1.0-rc7, allows you to select which program
stream to record. Program streams are called Virtual Channels in
the ATSC spec. Inkling also developed
With C30:KQED:PBS T30:20:00:030:0100000:PBS.3
If your machine is a Pentium 4, please turn off
hyperthreading in the BIOS, before recording using
Now, with pchdtvr 1.0-rc7, you can enable the use of GNU
Electronic Program Guide
In case you've still not quite gotten around to setting up MythTV, Andy Balaam's
freeguide is a nifty Java tool that can download XML
program guides, parse them, and display them in a nice
human-readable channel guide format. On Debian unstable,
These ATSC files are huge. Can I squash them?
Recorded ATSC streams tend to have
the occasional error in them, and, for many video transcoding
tools, this causes them to error out, and stop. One method to get
around this is to use mencoder -oac copy -ovc frameno -o frameno.avi ABC.3.ts mencoder -sws 2 \ -oac copy \ -ovc lavc -lavcopts \ vcodec=mpeg4:vhq:vbitrate=5000:vpass=1 \ -vf pp=hb/vb/dr/al/lb \ -vop scale=1280:720,crop=1280:720:0:0 -o ABC.3.avi ABC.3.ts mencoder -sws 2 \ -oac copy \ -ovc lavc -lavcopts \ vcodec=mpeg4:vhq:vbitrate=5000:vpass=2 \ -vf pp=hb/vb/dr/al/lb \ -vop scale=1280:720,crop=1280:720:0:0 -o ABC.3.avi ABC.3.ts Extracting the audio track
Sometimes, the video itself is of little interest, but
the audio track is worth preserving. So far, the only way I've
found that works to extract the A52 audio stream from ATSC
recordings is to use mplayer's mplayer -dumpaudio input.atsc a52dec -o wav stream.dump | lame - output.mp3 Strangely, using mplayer -frames 0 input.atsc 2>&1 |grep "AUDIO A52" # The mplayer output line we're interested in will look something like this: # # VIDEO MPEG2(pid=49)...AUDIO A52(pid=52) NO SUBS (yet)! PROGRAM N. 3 # # Convert the pid=52 into hex, and give it as "-t 0x34" parameter to extract_a52: extract_a52 -t 0x34 input.atsc | a52dec -o wav | lame - output.mp3 Multiple monitors
Using two monitors at the same time turns
out to be very convenient when viewing digital TV, as your
primary monitor can be used for other stuff, while keeping the TV
output running on the secondary monitor. For recent ATI graphics
cards, I try to explain the required configurations here. The way KDE makes the virtual desktops
twice as wide, when the Experience with various Linux distrosThe pcHDTV drivers for the HD3000 card built from the pcHDTV-1.6/kernel-2.6.x/driver module sources work with:
The Air2PC cardAccording to the Myth TV project documentation, the Air2PC is an ATSC card manufactured by BBTI, which makes nothing but digital TV capture cards. They are the maker of the SkyStar2 card (one of the best DVB cards available for sale currently). It uses a 4th generation NXT2002 demodulator. The Air2PC is supported by the linuxtv-dvb driver set. Support for the pcHDTV cards has also recently been added (see below). This driver set has been used for many years, and is designed for Digital TV. The Air2PC driver should be included in the 2.6.11 kernel, when it comes out. The Air2PC supports hardware filtering of the transport stream, which relieves the PCI bus of the entire transport stream, thus making the burden on your computer less when recording. The Air2PC card also supports QAM, which allows it to receive unencrypted digital cable. ATSC is used for over-the-air (terrestrial) broadcast of TV, as well as for most digital cable TV in North America (USA, Canada, and Mexico). The Air2PC card cannot be used to receive European DVB, although it does use drivers that are commonly used for European DVB, hence the confusion. The Air2PC cannot work with a satellite receiver, because the Air2PC only accepts 8VSB or QAM-modulated input. This means you can hook up only a TV antenna or cable TV wire to the Air2PC and get it to work. Satellite HDTV tends to use QPSK modulation, rather than 8VSB or QAM modulation. At the time of writing, March 2005, the Air2PC card was around $169.95, although it is out of stock until July 2005. More details may be found on the following pages: Mythic TV and Cyberstore The pcHDTV CardThe Linux folks at pcHDTV supply two HDTV cards with Linux drivers, the HD-2000 and HD-3000 cards. The HD3000 is an NTSC (analog capture) and ATSC (digital) card for HDTV in North America. The HD3000 uses a 2nd generation Oren demodulator. The HD3000 is supported by a modified bttv driver that will probably not be included in the mainline Linux kernel, as well as by the new DVB driver, which has been included starting from kernel 2.6.12-rc1. The HD3000 does not support hardware filtering, and the entire raw transport stream is sent over the PCI bus. The HD3000 in theory could support QAM for digital cable, and there have been some success reports on the pcHDTV forums of doing this using the new DVB drivers. The HD-3000 card has one RF input, one S-Video input, one Composite Video/Audio input, and one Stereo Audio output for NTSC. The HD-3000 card is not a universal PCI card. The HD-3000 card is a PCI 2.2-compliant 5-Volt card. That means there may be motherboards (that accept only 3.3 Volt cards) that the HD-3000 cannot be used with, so check that the PCI slot on your mother-board has a 5V key/riser toward the center of the motherboard and not a 3.3V-only key/riser toward the connector-end of the motherboard. In March 2005, the HD3000 card was $169.98 plus shipping, with a volume discount, e.g., you get a $9.96 discount if you buy two, from pchdtv. Mythic TV also sells them at $172.50 with free shipping. For driver support, see the pcHDTV HD-2000 and HD-3000 driver wiki. There's also a fledgling page on the LinuxTV Wiki. So What's the difference between the Air2PC card and the pcHDTV card?There's a comparison here. Video Card Considerations
Playback of HDTV streams uses quite a lot of
CPU resources. One possible way to get around the issue of HDTV
playback on slower machines is to use More Antenna ConsiderationsThe frequencies for the channels used for ATSC broadcasts tend to be higher, so the UHF antennas used for HDTV reception tend to be physically a lot smaller than the VHF antennas used for NTSC analog reception, because the wavelength of the signal is shorter. If the signal strength at your location is high enough, you
may be able to receive HDTV just fine using a plain loop of wire
hooked up to a piece of coaxial feed line. To get an idea of the
frequencies corresponding to the mysterious FCC channel numbers,
refer to the following list. This list of channels allotted by the FCC for digital
television may also be of interest. Either use the
If you are planning to really go all-out and design an antenna, it may be best to start by having a professional spectrum analysis performed at your location. Most satellite installation technicians will have the equipment to do this, and it will help to know whether you need to consider multipathing (reflections) of the received signals in your design. Redistribution Control Descriptor
The Redistribution Control Descriptor, also known
as the broadcast flag, is described on page 79 of the ATSC
Standard A_65B. To check whether the transport stream you are
receiving has this 0xAA flag set, you can build the NIST DASE ATSC/MPEG2 parser, which will print
out Update: The U.S. Court of Appeals in Washington ruled in May 2005 that the FCC does not have the authority to require manufacturers to implement the broadcast flag. DVB with the pcHDTV HD3000The DVB driver for the pcHDTV HD2000 and HD3000 card is now in kernels 2.6.12-rc1 and up. This guide tries to explain the steps to using this new DVB driver. The initial thread about DVB driver support in kernel 2.6.12-rc1 in the pcHDTV forums is here, and the Linuxtv folks also have this page about it. But let's go slow, and I'll try to explain all the steps in detail as best I can. For a similar guide showing how to configure the Air2PC card, see here instead. Build kernel 2.6.12.3
I built
kernel 2.6.12.3, downloaded on July 30,2005,
using this The module to load for terrestrial digital HDTV (8VSB ATSC) is
When compiling your kernel, cx88_dvb: Unknown symbol cx22702_attach
then it means you're missing the The config Device-drivers -> Multimedia devices -> [-] Video for Linux -> Video for Linux -> Video Adapters [-] Conexant 2388x (bt878 successor) support (CONFIG_VIDEO_CX88=m) [-] DVB support for cs2388x based TV Cards (CONFIG_VIDEO_CX88_DVB=m) Digital Video Broadcasting Devices -> [-] DVB for Linux (DVB=m) [-] DVB Core Support (DVB_CORE=m) Customise DVB Frontends -> [-] Conexant cx22702 demodulator (OFDM) (DVB_CX22702=m) [-] OR51132 based (pcHDTV HD3000 card) (DVB_OR51132=m) Build the kernel however you usually build your kernel. On
Debian, I used Manoj Srivastava's amazing tar jxvf linux-2.6.12.3.tar.bz2 cd linux-2.6.12.3 make gconfig fakeroot make-kpkg --initrd kernel_image modules_image
This produces a file called
apt-get install kernel-image-2.6.12.3_10.00.Custom_i386.deb
During installation, the initial RAMdisk is created. The
contents of the mount -t cramfs -o loop initrd.img-2.6.12.3 /mnt/test For more details on how to decide which modules will be included, and the order they'll be loaded, see here. If you need to remove the kernel package, because you have rebuilt it and want to try with a new one, use: dpkg -r kernel-image-2.6.12.3 dpkg --purge kernel-image-2.6.12.3 Probably all these details will seem excessive if you're already familiar with Debian, but this is one the first kernels I've built since I've been using Debian, so it's still fairly new to me. Download the Firmware
If you're
behind an HTTP application proxy firewall, set up your
http-proxy=http://your-proxy.your-domain:80
Download the firmware using the scripts contained in the
Linux kernel sources cd ~/linux-2.6.12.3/Documentation/dvb perl ./get_dvb_firmware or51132_qam perl ./get_dvb_firmware or51132_vsb
You can also download the firmware files from here on the pcHDTV downloads page. Now copy the files
cp dvb-fe-or51132-vsb.fw /usr/lib/hotplug/firmware/ cp dvb-fe-or51132-qam.fw /usr/lib/hotplug/firmware/ Sometimes, even though the firmware is present in the correct location, it still doesn't get uploaded by the hotplug system. If this is the case for you, it may be because of the same problem as described here and here. The fix I used on Debian was to add the following line to my
ENV{UDEVD_EVENT}=="1", RUN+="/sbin/udev_run_hotplugd"
I then restarted /etc/init.d/udev restart Load the DVB Kernel module
To load the module for digital over-the-air 8VSB ATSC,
use the following sequence of commands. The reason for all the
"remove" commands is that, after a reboot, you may find that some
modules you don't want have been loaded. It's safest to
really clean things up, before loading the modprobe -rv cx88_blackbird modprobe -rv cx88-dvb modprobe -rv cx8800 modprobe -v cx88-dvb This should cause the device directory
crw-rw---- 1 root video 212, 4 2005-07-31 22:42 /dev/dvb/adapter0/demux0 crw-rw---- 1 root video 212, 5 2005-07-31 22:42 /dev/dvb/adapter0/dvr0 crw-rw---- 1 root video 212, 3 2005-07-31 22:42 /dev/dvb/adapter0/frontend0 crw-rw---- 1 root video 212, 7 2005-07-31 22:42 /dev/dvb/adapter0/net0 crw-rw---- 1 root video 212, 68 2005-07-31 22:42 /dev/dvb/adapter1/demux0 crw-rw---- 1 root video 212, 69 2005-07-31 22:42 /dev/dvb/adapter1/dvr0 crw-rw---- 1 root video 212, 67 2005-07-31 22:42 /dev/dvb/adapter1/frontend0 crw-rw---- 1 root video 212, 71 2005-07-31 22:42 /dev/dvb/adapter1/net0 To unload the modprobe -rv cx88-dvb Output of the load command insmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/dvb-pll.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/cx22702.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/video-buf.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/dvb-core/dvb-core.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/video-buf-dvb.ko insmod /lib/modules/2.6.12.3/kernel/drivers/base/firmware_class.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/or51132.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/videodev.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/tveeprom.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/btcx-risc.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/common/ir-common.ko insmod /lib/modules/2.6.12.3/kernel/drivers/i2c/algos/i2c-algo-bit.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/cx88/cx88xx.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/mt352.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/cx88/cx8802.ko insmod /lib/modules/2.6.12.3/kernel/drivers/media/video/cx88/cx88-dvb.ko Output of the unload command rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/cx88/cx88-dvb.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/cx88/cx8802.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/mt352.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/cx88/cx88xx.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/i2c/algos/i2c-algo-bit.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/common/ir-common.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/btcx-risc.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/tveeprom.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/videodev.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/or51132.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/base/firmware_class.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/video-buf-dvb.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/dvb-core/dvb-core.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/video/video-buf.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/cx22702.ko rmmod /lib/modules/2.6.12.3/kernel/drivers/media/dvb/frontends/dvb-pll.ko Using the DVB kernel modules
Get the latest cvs -z3 -d ':pserver:anonymous@cvs.linuxtv.org:/cvs/linuxtv' co -P dvb-apps If you're behind an HTTP application proxy firewall, you'll need to add the proxy to the command like this: cvs -z3 -d ':pserver;proxy=your-proxy.your-domain;proxyport=80:anonymous@cvs.linuxtv.org:/cvs/linuxtv' co -P dvb-apps Some distributions include a Build the Go into the util/scan directory, and run the following example: cd dvb-apps/util/scan && ./atscscan atsc/us-NTSC-center-frequencies-8VSB The kernel module will try to load the firmware for the HD3000 card, at this point. Check your "dmesg" output. If you see this in "dmesg", then the firmware isn't being uploaded by the hotplug subsystem: or51132: Waiting for firmware upload(dvb-fe-or51132-vsb.fw)... or51132: No firmware uploaded(timeout or file not found?) As described in the section above, even though the firmware is present in the correct location, it may still not get uploaded by the hotplug system. Please try the fix described in that section. Once the firmware loads successfully, or51132: Waiting for firmware upload(dvb-fe-or51132-vsb.fw)... or51132: Version: 10001134-19430000 (113-4-194-3) or51132: Firmware upload complete. Once the firmware is loaded, the cd dvb-apps/util/scan && ./atscscan atsc/us-NTSC-center-frequencies-8VSB
The full output of the above command is here, but only the summary section
dumping lists (26 services) KNTV-HD :207000000:8VSB:65:68:4 NBC Wea :207000000:8VSB:81:84:5 KBWB-HD :503000000:8VSB:49:52:3 KBWB-SD :503000000:8VSB:65:68:4 KGO-DT :533000000:8VSB:49:52:3 KGO-DT :533000000:8VSB:65:68:4 KTSF-D2:551000000:8VSB:49:68:4 KTSF-D1:551000000:8VSB:49:52:3 KPIX DT:563000000:8VSB:49:52:1 KQED-HD:569000000:8VSB:49:52:3 ENCORE:569000000:8VSB:65:68:4 KMTP Digital Television:587000000:8VSB:49:52:3 Telefutira:593000000:8VSB:49:52:3 KCNS-DT:623000000:8VSB:49:52:3 KKPX Faith:635000000:8VSB:97:100:6 KKPX Worship:635000000:8VSB:81:84:5 KKPX Pax East:635000000:8VSB:65:68:4 KKPX Digital Television:635000000:8VSB:49:52:3 KCSM-TV:647000000:8VSB:33:36:2 Jazz-TV:647000000:8VSB:49:52:3 KBHK-DT:659000000:8VSB:49:52:1 KTVUHD:725000000:8VSB:49:52:3 KTVU-DT:725000000:8VSB:65:68:4 KRON-SD:731000000:8VSB:49:52:3 KRON-HD:731000000:8VSB:65:68:4 KTNC DIGITAL TELEVISION:767000000:8VSB:49:52:3 Done. Creating the
|
I studied engineering at Université de Liège for a year, then at Trinity
College Dublin for four more (and where I wish I had paid more attention
during the networking lectures). I've always been curious about audio and
video on computers, and Linux has been truly an amazing platform for learning
about these areas.