Linux Based PVR System using MythTV and an Xbox

1. Introduction

Video tapes can be so annoying, you can never remember what is on which tape and once you’ve found the correct tape you’ve then got to spend ten minutes fast-forwarding and rewinding the tape to find the program you want to watch, and what about finding a spare tape to recording something on when you’re in a hurry? There has to be an easier way…

…and there is – a Personal Video Recorder (PVR) system that can record television digitally to a hard disk that will have hundreds of hours of recording capacity. With an Electronic Program Guide (EPG) you can quickly see what’s on and schedule recording of a show or even an entire series with a couple of clicks. You can even pause and re-wind live TV, so no more missing your favourite show when someone decides to call you just as it gets to the exciting bit.

Set-top-box PVR systems are readily available but buying one off the shelf is boring and may not offer all the functionality you want, so why not build your own for very little for next to nothing? All you need is a PC, a TV capture card and lots of free disk space.

2. My PVR System

The system that I have spent the last few days setting up uses a desktop Linux PC which contains a Hauppauge PVR-250 capture card and runs MythTV to work as the video recorder, a Linux file server that has a nice big hard disk in it to store all the recordings, and a modded Xbox running Xbox Media Center and a MythTV frontend script to allow you
to watch and schedule recordings from the sofa.

PVR System

2.1. TV Capture Cards

As the computer will be doing the recording it needs someway of getting a TV signal and to do that it needs a TV capture card. The ones that seem to work the best are Hauppauge ones. The basic WinTV cards will decode the analog TV signal and provide a raw digital version of the signal to the computer. The digital signal is not compressed and would therefore take up huge amounts of disk space, as such the computer it self will need to compress the data so its more manageable. This task is obviously quite CPU intensive and will require a reasonably fast PC.

A better choice is something like the Hauppauge PVR-250 card. This includes an onboard MPEG-2 encoder which saves your computers CPU from having to do any encoding. This means that recording a TV program requires virtually no CPU usage at all! Both the cards mentioned here are analog so if you’re interested in using the Freeview system then you will want to go for something like the Hauppauge Nova-T card.

2.2. MythTV

MythTV is a homebrew PVR project for Linux that has been under heavy development for two years now and is quite usable and contains lots of features. One of the very nice design features of MythTV is that the functionality is split in half – the backend half runs on the computer(s) that contains the TV card(s) and these manage all the scheduling and recording. The frontend half can then be run on separate computer(s) and pull the TV signal or recordings over the network from the backend server(s). This means you can have you TV card in your fast noisy desktop PC and use a nice small quiet PC sitting under the TV as the frontend. The use of multiple backends enables the use of multiple capture cards and the ability to record several programmes at the same time on different channels.

MythTV is also extensible with numerous plugins including:

  • MythVideo: A Player for watching video not recorded with MythTV.
  • MythMusic: A jukebox-like music player and music collection manager (includes CD ripping).
  • MythDVD: DVD management (includes ripping to disk)
  • MythGallery: Online photograph gallery viewing and management.
  • MythNews: RSS feed news reader.
  • MythWeather: Displays weather forecast obtained from the network.
  • MythBrowser: A small web browser for TV viewing.
  • MythGame: Frontend to game console emulators.
  • MythWeb: Allows remote control of MythTV from web browers on other computers.
  • MythPhone: Supports Internet phone calls from your TV via SIP

MythTV Frontend

3. Getting the Hauppague PVR-250 working under Linux (Installing the IVTV driver)

The system I have setup uses a Hauppague PVR-250 in a Linux PC running the Ubuntu: Breezy Badger distribution. To get this TV card working under Linux you need to download, compile, and install the IVTV driver. At the time of writting the current stable release of the driver is 0.4.1.

Compiling the driver was as simple as doing:

tar xzf ivtv-0.4.1.tar.gz
cd ivtv-0.4.1
export CC=gcc-3.4
make
sudo make install

You then need to download some firmware files in order to use the driver you just compiled:

wget ftp://ftp.shspvr.com/download/wintv-pvr_150-500/inf/pvr_2.0.24.23035.zip 
mkdir firmware 
cd firmware 
unzip pvr_2.0.24.23035.zip sudo cp HcwFalcn.ROM /usr/lib/hotplug/firmware/v4l-cx2341x-enc.fw sudo cp HcwMakoA.ROM /usr/lib/hotplug/firmware/v4l-cx25840.fw

Once you’ve copied the firmware files to the correct place it should then just be a matter of typing

sudo modprobe ivtv

If you then check the output of dmesg you should see something like this:

ivtv:  ==================== START INIT IVTV ====================
ivtv:  version 0.4.1 (tagged release) loading
ivtv:  Linux version: 2.6.10 preempt K7 gcc-3.3
ivtv:  In case of problems please include the debug info between
ivtv:  the START INIT IVTV and END INIT IVTV lines, along with
ivtv:  any module options, when mailing the ivtv-users mailinglist.
ivtv0: Autodetected WinTV PVR 250 card (cx23415 based)
ACPI: PCI Interrupt Link [LNKC] enabled at IRQ 11
PCI: setting IRQ 11 as level-triggered
ACPI: PCI interrupt 0000:00:0a.0[A] -> GSI 11 (level, low) -> IRQ 11
ivtv0: Unreasonably low latency timer, setting to 64 (was 32)
tveeprom: ivtv version
tveeprom: Hauppauge: model = 48015, rev = G711, serial# = 6231975
tveeprom: tuner = Philips FI1246 MK2 (idx = 11, type = 1)
tveeprom: tuner fmt = PAL(I) (eeprom = 0x10, v4l2 = 0x00000010)
tveeprom: audio processor = MSP3415 (type = 6)
tveeprom: decoder processor = Type 0x00 (type = 0)
ivtv0: i2c attach to card #0 ok [client=tveeprom, addr=50]
tuner (ivtv): chip found at addr 0xc2 i2c-bus ivtv i2c driver #0
ivtv0: i2c attach to card #0 ok [client=(tuner unset), addr=61]
saa7115 0-0021: ivtv driver
saa7115 0-0021: saa7115 found @ 0x42 (ivtv i2c driver #0)
ivtv0: i2c attach to card #0 ok [client=saa7115, addr=21]
msp3400 0-0040: ivtv driver
msp3400 0-0040: chip=MSP3415G-B8 +nicam +simple +simpler +radio mode=simpler
msp3400 0-0040: msp34xxg daemon started
ivtv0: i2c attach to card #0 ok [client=MSP3415G-B8, addr=40]
ivtv0: loaded v4l-cx2341x-enc.fw firmware (262144 bytes)
ivtv0: loaded v4l-cx2341x-dec.fw firmware (262144 bytes)
ivtv0: Encoder revision: 0x02050032
ivtv0: Decoder revision: 0x02020023
ivtv0: Allocate DMA encoder MPEG stream: 128 x 32768 buffers (4096KB total)
ivtv0: Allocate DMA encoder YUV stream: 161 x 12960 buffers (2048KB total)
ivtv0: Allocate DMA encoder VBI stream: 80 x 26208 buffers (2048KB total)
ivtv0: Allocate DMA encoder PCM audio stream: 455 x 4608 buffers (2048KB total)
ivtv0: Create encoder radio stream
tuner: type set to 1 (Philips PAL_I (FI1246 and compatibles)) by ivtv i2c driver #0
ivtv0: Initialized WinTV PVR 250, card #0
ivtv:  ====================  END INIT IVTV  ====================

You can then check whether your card is working by doing:

cat /dev/video0 > test.mpg

Press CTRL+C after a few seconds and then play the video back using mplayer of xine or your favourite video player. If you see a TV programme (or more likely snow) then your capture card is working.

NOTE:
These are just some brief instructions on installing the IVTV drivers on Ubuntu Linux. For more detailed intructions and help please see the IVTV website at http://ivtvdriver.org.

4. MythTV

4.1. Installing on Ubuntu

As described above, MythTV is a homebrew PVR project for Linux. If, like me, you’re using Ubuntu then you can simply use apt-get to install MythTV. The MythTV packages are in the multiverse respository so make sure you have the following lines in your /etc/apt/sources.list file and then do a sudo apt-get update:

deb http://archive.ubuntu.com/ubuntu breezy multiverse
deb-src http://archive.ubuntu.com/ubuntu breezy multiverse

MythTV consists of two halves – a backend and a frontend. The backend is the system that has the TV cards installed in it and will manage all the recordings and streaming of the live TV. In my setup then I have a desktop Linux PC with the Hauppauge PVR-250 which I am using as the backend. It is possible to have more than one backend allowing you to have multiple systems with tv cards doing the recordings. All the settings and program guide data are stored in a MySQL database which will reside in a Master backend server. I have not apptempted running a system with multiple backends so please check the MythTV documentation on how to do this.

To install a MythTV backend system on an Ubuntu system simply do:

sudo apt-get isntall mythtv-backend mythtv-database mythweb

This will install the MythTV backend system along with the MySQL database and a web-based interface to the program guide and scheduling system on your computer. You will then need to follow the instructions provided by apt-get and run the mythtv-setup program to configure the backend system. You can do this by typing:

sudo su mythtv -c "mythtv-setup"

You now need to work your way through all of the steps to fully configure MythTV.

For detailed instructions on configuring MythTV please see section 9 of the MythTV documentation.

4.2. Using

Configuring MythTV can seem like a nightmare but with any luck you will be able to get it up and running. If all is well then at this stage you should have the backend configured and running on your PC. This is the machine that will manage the recording schedules and program guide data as well as stream live TV to your MythTV frontends (described later).

The MythTV backend program will run quietly in the background and can get on with using your PC without even noticing it is running. Programmes can be scheduled for recording via the MythTV frontends and via the the MythWeb web-interface which should be available via http://localhost/mythweb/.

Now you can schedule recordings via a web-interface and have MythTV record the programmes on your desktop PC, but wouldn’t it be nice if you could watch the recordings on your TV? For that you need a system to run a MythTV frontend. The computer that runs the frontend doesnt need to be terribly powerful meaning that you can use a nice small quiet system such as a mini-itx. A mini-itx system will run virtually silently, consume very little power, and (if you buy the right case) shouldn’t look out-of-place sitting on top of you DVD player or VCR.

Once you’ve got a suitable system to use as a MythTV frontend simply install Linux on it and then put the MythTV frontend software on. If you’re using Ubuntu then it’s as simple as doing:

sudo apt-get install mythtv-frontend

If you want any of the extra modules to add more functionality to your frontend then you can install the following extra packages as well:

  • mythbrowser – A small web browser module for MythTV
  • mythdvd – DVD add-on module for MythTV
  • mythgallery – Image gallery/slideshow add-on module for MythTV
  • mythgame – A game frontend (xmame, snes, nes, pc) module for MythTV
  • mythmusic – Music add-on module for MythTV
  • mythnews – An RSS feed news reader module for MythTV
  • mythphone – video conferencing add-on module for MythTV
  • mythvideo – A generic video player frontend module for MythTV
  • mythweather – Weather add-on module for MythTV
  • mythtv-themes – Additional themes for MythTV

5. Using Xbox Media Center (XBMC) as a MythTV Frontend

At the end of the last section I described how you could use a quiet small form-factor PC as a MythTV frontend, however I am already using a modded Xbox running Xbox Media Center to watch videos, play MP3s, and view photos on the TV and I dont want to replace it or have to use another box just for watching TV recordings I’ve made using MythTV.

Fortunatly there is a MythTV Frontend plugin for XBMC on sourceforge. Using this plugin you can still use XBMC to watch videos, play MP3s and view photos, but you can also now use it to watch TV recordings, schedule recordings, and watch live TV with the ability to pause and rewind it. What more could you possibly want?

The following screenshots are from the sourceforge project page:

5.1. Installing XBMC MythTV

I will assume that you already have a modded Xbox with XBMC installed. I am using XBMC CVS snapshot release 18th Dec 2005. You can download XBMC MythTV version 0.18.2 released on September 28th 2005 from here or download the latest version from CVS with the following commands:

cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/xbmcmythtv login
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/xbmcmythtv co -P xbmcmythtv

You then need to upload the xbmcmythtv directory and everything below it to your XBMC/scripts directory on your xbox. Start XBMC and run the mythtvmain.py script. Go into the Settings screen and specify the connection details and paths.

On your MythTV backend machine you will want to export your MythTV recordings and cache folder via Samba so that the Xbox can access it. Edit /etc/samba/smb.conf and add the following lines:

[mythtv]
path = /var/mythtv
read only = no
guest ok = yes

I am assuming here that your MythTV cache and recordings folders are set up like this (if not you will need
to modify the samba configuration):

/var/mythtv
/var/mythtv/cache
/var/mythtv/recordings

If you are using the Project Mayhem III skin then you can add a menu button for MythTV by editing the XBMC/skin/Project Mayhem III/pal/DialogSubMenu.xml skin file. Look for a SubMenu button that has the visible attribute set to no and then:
– set the visible attribute to yes,
– set the label attribute to “MythTV”,
– and set the execute attribute to q:scriptsxbmcmythtvmythtvmain.py.

6. Conclusion

I have been using my Xbox as a media center for over a year now and it gets used for that far more than it does for games. In fact the main reason I got an Xbox was to hack it and turn it into a media center. The only thing I felt lacking was the ability to use it as a PVR system which is hardly the fault of the Xbox or XBMC as there is no way to add a TV capture card to the Xbox.

The MythTV project and the MythTV plugin for XBMC turned this around and although I have only been using the new PVR capabilities for a couple of days now I can see it being far more usefull for recording TV programmes than messing around with video tapes. Of course, the other advantage of using MythTV is that the recordings are available on my file server as MPEG-2 files so I can watch them on the TV or on a computer.

The next step will be to add a Hauppauge Nova-T card to the system so that I can receive a higher quality signal than I currently get on the analog system and so that I can record more than one program at the same time. Oh, and digital gives me a few more channels
as well :-)