In the last five years, digital video recorders (DVRs) have become all the rage, giving television addicts more and more control over viewing habits. But while TiVo and devices like it (such as the ReplayTV, DishPlayer, DIRECTV Plus, and locally-branded OEM versions of Motorola’s digital cable set-top boxes) have virtually obsoleted the hassle of manually programming and swapping tapes in and out of the VCR, DVRs still have a long way to go to become a centralized media server. Digital nirvana is a single device that combines an Internet-connected PC, the TiVo, an enormous hard disk, and an audio and video streaming server.
But if you’re an early adopter and love to play with PC hardware, you can reach the digital apex now. By mixing Linux, a TV tuner and video capture peripherals, and some nifty open source and commercial software, you can build a home media server that does everything. If TiVo no longer turns you on or you love to play with all kinds of multimedia files, building this box is the project for you.
Acquiring a Video Capture Card
The first thing to buy is a video capture/TV tuner card for the PC that you’re going to designate as your media server. Currently, only one video capture/TV tuner chipset has open source drivers that work â€” the Conexant CX234xx chipset, which uses the ivtv Linux kernel module available from http://ivtvdriver.org. (The full list of supported hardware can be found at http://ivtvdriver.org/index.php/Supported_hardware.) However, I’ll make it easy for you. There are only two cards you really should be looking at: the PVR-150MCE and the PVR-500MCE from Hauppauge, Inc. The latter card is shown in Figure One.
FIGURE ONE:The Hauppauge PVR-500MCE digital video capture card
The main difference between the two Hauppauge cards is that the PVR-150MCE has a single TV FM radio tuner and the PVR-500MCE has two. Choose the latter if you want to record two shows at a time, or record one show and watch one live simultaneously. The PVR-150MCE also has a built-in connection for attaching an infrared blaster cable and IR blaster to your satellite receiver box or your cable TV box, and comes with a remote control. To control a satellite or cable TV box with the PVR-500, you use a null modem 9-pin serial cable connected from the PC to the cable box/satellite receiver, provided your set top has a serial connection. You can also use a separate IR tuner card (more on that later).
Both cards have a coaxial and an S-Video connector (the PVR-500MCE has two coaxial connectors) and both have Composite inputs for video and RCA stereo input jacks. The PVR-500MCE also has two on-board A/V headers on the PCB to connect to two more A/V sources with an additional set of cables. The PVR-150MCE has one to add an additional source. It’s also possible to stuff more than one of these cards into your PC to achieve four or more video input sources or tuners.
The PVR-150MCE has a street price of about $60, whereas the PVR-500MCE is about $130. (Another card, the PVR-350MCE also exists, but it’s about the same price as the PVR-500MCE and it only has one tuner, so you might as well disregard it unless you need its S-Video output capability.)
If you’re looking to go HDTV, you might also want to look at the AirStar-HD5000AV-PCI Air2PC card (http://mythic.tv/product_info.php?products_id= 46), which goes for $99 and is sold in North America by StormLogic. It has a single HDTV tuner for over the air, and can accept signal sources from HDTV DirecTV or digital cable.
The rest of this article focuses on the PVR-500MCE.
Building Your Media Server
Chances are you’re going to want to use a dedicated PC as your Linux media server. While you can integrate the hardware and function of the media server into an existing desktop PC and run everything on a solitary box, you’re going to have to live with a very specific configuration and software stack that works well as a media server.
In researching this article, I went thru a number of different Linux distribution and hardware combinations to find the perfect all-in-one server and desktop box, only to discover there really is no such thing. Also, given the finicky ivtv kernel driver and what kernel revisions and distributions it likes, you don’t want to reconfigure your desktop box with the media software every time you want to upgrade your distro. Build the media and leave it alone so it can perform its job as an appliance.
For a media server, purchase an inexpensive Pentium 4, Celeron, Athlon 64, or Sempron main board with an integrated sound card and NIC from Abit or ASUS. If you go the Athlon 64/nVidia Nforce chipset route, stick with the Hauppauge PVR-500MCE card for your capture device â€” you’ll avoid the headaches I had with the PVR-150MCE while researching this article. There’s no need to purchase the pinnacle of technology, because most of the processing workload is done by the capture card. (You’d be surprised just how skimpy the processor in the TiVo is â€” which, by the way, runs on Linux.)
In fact, if you don’t want to piece the thing together and build most of the box yourself, your average $400 Taiwanese PC special from CompUSA, COSTCO, TigerDirect, or Dell is just fine. Simply add a 100 GB hard disk and a total of 1GB of memory. If you have parts lying around, like spare CD/DVD ROM drives, hard drives, video cards, and such â€” you won’t need a stellar video card on the server either, the basic $25-$50 nVidia or ATI or Intel that plain jane machines come with these days is just fine.
Prepping the Operating System
Once your media server is built and it powers up cleanly on POST, recognizing all of your memory, your DVD/CD-ROM and your hard drives, install Linux. For the purposes of this article, and to make life easier for you, I’ve chosen Ubuntu Edgy 6.10. It’s free, I was able to verify everything I did for this article worked on Ubuntu, and people seem to like the Ubuntu flavor of Linux.[ See the Ubuntu fearture story beginning on page XX.] (You can likely get the ivtv driver to work on Debian, Fedora Core 6, OpenSUSE 10.2, and other distros as well, but your mileage may vary.)
Download the ISO image for the regular, 32-bit version of Ubuntu Edgy 6.10 and burn it to a CD. Currently, the ivtv kernel module driver has problems with 64-bit Linux distributions, so this is another reason why you’ll want to separate your regular desktop PC from this system, unless you are happy running 32-bit Ubuntu for everything. Go through the default installation, and when finished, install all of the multimedia audio/video codecs, multimedia players, nVidia drivers (if you have an nVidia card), and Java packages from Automatix2 using the procedures outlined in â€œTweaking Ubuntuâ€ from the December 2006 issue of Linux Magazine (http://www.linux-mag.com/content/view/2828/). Just be sure to use the Edgy repositories instead of the Dapper ones.
Installing and Verifying the ivtv Driver and Conexant Firmware
After running Automatix2 and installing the multimedia codecs and the Sun Java JRE, pull up a terminal window, and enter the following commands in sequence.
Then set up the debconf facility to allow the display of End User License Agreements:
# sudo dpkg-reconfigure debconf
Choose â€œDialogâ€ and then exit debconf.
Next, install the Conexant chipset firmware for the Hauppauge board:
# sudo apt-get install ivtv-firmware
Now, prepare module-assistant. Every time a new kernel is installed (which really, you should only need to do each time you completely rebuild your media server) , you must rerun these commands to reinstall the driver for that kernel:
After the modules are installed, insert the driver into the kernel:
# sudo modprobe ivtv
Next, verify that the module is running and the firmware is loaded.
# dmesg | more
You should see a series of output in the kernel message log that looks something like Figure Two.
FIGURE TWO:Expected output of dmesg after you’ve loaded the ivtv module
[17179959.308000] Linux video capture interface: v1.00
[17179959.312000] ivtv: ==================== START INIT IVTV ====================
[17179959.312000] ivtv: version 0.7.0 (tagged release) loading
[17179959.312000] ivtv: Linux version: 2.6.17-10-generic SMP mod_unload 586 REGPARM gcc-4.1
[17179959.364000] tveeprom 3-0050: Hauppauge model 23552, rev E687, serial# 10025397
[17179959.364000] tveeprom 3-0050: tuner model is Samsung TCPN 2121P30A (idx 87, type 70)
[17179959.364000] tveeprom 3-0050: TV standards NTSC(M) (eeprom 0x08)
[17179959.364000] tveeprom 3-0050: second tuner model is Philips TEA5768HL FM Radio (idx 101, type 62)
[17179959.364000] tveeprom 3-0050: audio processor is CX25843 (idx 37)
[17179959.364000] tveeprom 3-0050: decoder processor is CX25843 (idx 30)
[17179959.364000] tveeprom 3-0050: has radio, has no IR remote
[17179959.364000] ivtv0: This is the first unit of a PVR500
[17179959.684000] cx25840 3-0044: cx25843-23 found @ 0x88 (ivtv i2c driver #0)
[17179964.112000] cx25840 3-0044: loaded v4l-cx25840.fw firmware (16382 bytes)
[17179964.212000] wm8775 3-001b: chip found @ 0x36 (ivtv i2c driver #0)
[17179964.896000] ivtv0: loaded v4l-cx2341x-enc.fw firmware (262144 bytes)
[17179965.112000] ivtv0: Encoder revision: 0x02050032
[17179965.112000] ivtv0: Allocate DMA encoder MPEG stream: 128 x 32768 buffers (4096KB total)
[17179965.276000] ivtv0: Initialized WinTV PVR 500 (unit #1), card #0
If you have more than one tuner or more than one Hauppauge board installed, you’ll see several instances of this, enumerating as many ivtv tuner devices as you have. If you see any error messages, consult the Ubuntu wiki at https://help.ubuntu.com/community/Install_IVTV_Edgy.
To make the driver load every time the machine reboots, issue the command:
# sudo sh -c 'echo ivtv >>/etc/modules'
Testing the Video Capture Interface
Once you got your ivtv driver ducks in a row, test the video capture interface. At this point, I assume you have a either a powered TV antenna (a la RadioShack) connected to the coaxial tuner port (s) on the Hauppauge board (s), or have video cables from your cable TV or satellite receiver coming in thru the composite, S-Video, or the coax tuner, or a combination of the above.
Issue the following command from a terminal prompt:
# sudo mplayer /dev/video0
If you followed all the steps in the operating system installation section with Automatix2, you should now see video in MPlayer, as shown in Figure Three.
FIGURE THREE:The MPlayer application displays video captured from the ivtv driver interface.
While the video in MPlayer is playing, you can open up another terminal window, and issue the following in series:
Type in a command for each port you have to cycle through all of the available video input sources and view them in MPlayer. This is a good way of diagnosing simple cable connectivity problems. Be sure to note of which numerical value corresponds to what video source (such as Composite Video being 2), as it might come in handy later.
Choosing Your Media Server Software
Once you’ve verified that your video capture hardware is working, you can decide what media server Server suite to use. Some of this may be dependent on what combination of cable/satellite set-top boxes you have.
The two major media server suites for Linux today are MythTV (http://www.mythtv.org), which is an open source solution that requires MySQL connectivity, and SageTV (http://www.sagetv.com), which is a commercial package that is entirely based on Java. Both are very good solutions, but I prefer SageTV because it has commercial support, it’s easy to set up, and it has a lot of features. It’s also not that expensive ($80, $99 with one Placeshifter license), and supports â€œPlaceshifterâ€ Java clients for Linux, Windows, and Mac OS X, so you can view recorded multimedia content and live TV from remote networked machines. SageTV also sells an Ethernet-connected Media Extender device for $110.00 (an 802.11g wireless version is $160) that allows you to turn any TV set with S-Video or composite inputs into a full blown SageTV client. That means you can centralize on one SageTV server, and every TV set in your house can have access to the same content. No more juggling two different TiVo’s in your bedroom and living room with two different wish lists.
Issue the following command, and enter your SageTV license key:
# sudo ./keygen.sh
Next, start the SageTV server:
# sudo ./startsage
Connecting to SageTV
Once the SageTV server is running, you can connect to it via:
# sudo /opt/sage/client/sageclient.sh
The client searches for the server on the network; select it and save it to the list in the launcher user interface. You can also connect to it directly by creating an entry for 127.0.0.1 or locahost.
The first time you connect to the SageTV server, you’ll be guided thru a series of wizards (a la TiVo) to configure your time zone, your locale, channel guides, as well as select your input sources. You’ll then be able to watch Live TV and set up your program lists. Figure Four shows the SageTV main menu.
FIGURE FOUR:The SageTV main menu resembles those of other DVRs
If you have an nVidia card (of relatively recent vintage), you may need to add the following line to the SageTVPlaceshifter.properties file located in the /root/.sagetv directory (or the /home subdirectory of the user on the machine you launched the client from):
This setting sets the client for software OpenGL rendering as opposed to hardware overlay rendering (which ATI cards and older nVidia cards use). Otherwise, you may have some issues with screen flickering and menu transparency. Additionaly, if you are using Composite inputs, and if you have trouble seeing video, you’ll want to probably tweak this field in the Sage.properties file in /opt/sagetv/server:
(The enumeration value will vary from machine to machine.) By default, the value is set to 1. On my machine with a PVR-500MCE, I had to set it to 2 (as determined from the ivtvctl section earlier). As the PVR-500MCE has twin TV tuners, there are two instances of this field in the Sage.properties file. I had to set this value twice.