PVR for Linux HOWTO
What we found to work best when setting up a PVR system on Linux
CS 488 - Extreme Linux - George K. Thiruvathukal
Project Team: Peter Aarestad, Laura Griffel, Doris Woods
Introduction
In our work over the past few months, we have come across several HOWTO documents that have guided us in our attempt to set up a PVR on Linux. In particular, this HOWTO has proven to be the most useful, and will be the one we reference the most often - much of the configuration information you will read here comes from that HOWTO. In this document we will attempt to summarize what worked best for our group.
Here are the topics we plan to cover in this document:
- Hardware requirements
- Particulars when installing Gentoo Linux
- Getting sound to work
- Getting the DVD player to work
- Setting up the PVR card
- Installing MythTV
- Configuring Freevo
Keep in mind that this HOWTO makes references to certain versions of software. The software we use here will doubtless be updated as time passes, and we may not keep track of every single software package update. In general, you should use the latest version of the software available - if we feel a certain version is necessary, we will note that.
A FURTHER DISCLAIMER: We make NO WARRANTY as to the fitness of this information. If you decide to use this for some commercial purpose, feel free, but we CANNOT be held liable if your customers' PVRs spontaneously combust. Caveat lector.
Hardware requirements
Different needs require different hardware, obviously. However, we have found that it does not take a great deal of computer horsepower to get decent performance out of multimedia programs. Here are the specs of our system:
- Pentium III, 450 MHz processor
- 192 MB RAM
- Two 40-GB Hard drives (one system drive, one data drive)
- Built-in Yamaha sound card
- ATI Rage 128 video card, 16 MB VRAM
- Combo CD/DVD drive
- Hauppauge WinTV PVR250 PCI card with on-board MPEG encoder
The last item is the most important - it's the hardware that drives live TV viewing and recording. It's also the trickiest to set up, due to the fact that the company chooses only to support Windows machines. Thanfully, clever hackers have found a way to use Hauppauge's own Windows-only software on Linux - we'll cover how later on.
Particulars when installing Gentoo Linux
We initially followed the general installation instructions provided by Gentoo. We attempted to get things working with the 2.4 kernel, and got as far as getting sound and the DVD player to work. However, we ran into trouble with the PVR card. At this point, we discovered the aforementioned HOWTO that describes in detail how to install MythTV along with the particular model of Hauppauge WinTV card. However, it recommends using the 2.6 kernel, so we had to backtrack and recompile the kernel.
Here are the options (besides those mentioned in Gentoo's install instructions) that should be enabled in the kernel configuration, mostly copied from Section 3 in the MythTV HOWTO. The "*" is equivalent to "Y" in make menuconfig (meaning that option is compiled directly into the kernel), and "M" means to compile that option as a module.
TODO: Add options for DVB drivers to list below
- Device Drivers --->
- Multi-device support (RAID and LVM)
- <*> Device mapper support
- <*> ioctl interface version 4
- Input device support --->
- <*> Event interface
- Character devices --->
- Serial Drivers
- <*> 8250/16550 and compatible serial support
- Linux InfraRed Controller --->
- <M> Linux InfraRed Controller
- <M> I2C Driver
- <*> Enhanced Real Time Clock Support
- Serial Drivers
- I2C support --->
- <M> I2C support
- <M> I2C device interface
- I2C Hardware Bus support --->
- <M> ISA Bus support
- <M> (YOUR VIDEO CARD HERE)
- I2C Hardware Sensors Chip support --->
- <M> EEPROM (DIMM) reader
- <M> Winbond W83781D, W83782D, W83783S, W82627HF, Asus AS99127F
- Multimedia devices --->
- <M> Video For Linux
- Video For Linux --->
- <M> BT848 Video For Linux
- Graphics support --->
- <*> Support for frame buffer devices
- Sound --->
- <*> Sound card support
- Advanced Linux Sound Architecture --->
- <M> Advanced Linux Sound Architecture
- <*> OSS API emulation
- <M> OSS Mixer API
- <M> OSS PCM (digital audio) API
- <M> RTC Timer support
- PCI devices --->
- <M> (YOUR SOUND CARD HERE)
- Multi-device support (RAID and LVM)
- File systems --->
- <*> (YOUR FILESYSTEM HERE)
For our filesystem, we laid out our disks as follows:
- Disk 1 (hda)
- hda1: 50 MB, mountpoint /root, ext2 filesystem
- hda2: 1 GB, swap
- hda3: ~38.5 GB, mountpoint /, ext3 filesystem
- Disk 2 (hdb)
- hdb1: entire disk (40 GB), mountpoint /data, ext3 filesystem
You can choose any filesystem you'd like, but the above choices of ext2 and ext3 are what the Gentoo installation process recommends.
Before installing software beyond the base software, set up your USE variable in /etc/make.conf thusly:
USE="x86 mmx 3dnow sse alsa avi crypt \
cscope dvd flac gif imlib jpeg lirc \
mad mpeg oggvorbis opengl png quicktime \
sdl tiff truetype X xmms xv zlib \
-arts transcode xinerama -nls net \
joystick matroska"
In addition, you should emerge sudo as soon as possible. sudo is a great command that allows you to run commands as root without actually having to su every time. We will be using sudo when describing the commands to run below. We also used KDE as our window manager, but it's obviously up to you what you use, though. :) Other packages to emerge at this point:
xfree, gdm, mysql, vorbis-tools, a52dec,
lame, vim, divx4linux, freetype, pciutils,
xvid, flac, fontconfig, win32codecs
Getting sound to work
For sound, we use the Linux standard, ALSA. Before going any further, ensure that your sound card is supported by ALSA, and that you chose the correct sound card module in the kernel configuration above. Once you've done that, run these commands:
sudo emerge sync
ALSA_CARDS='YOUR_CARD_TYPE_HERE' sudo emerge \
\>=media-sound/alsa-driver-1.0.2c
ACCEPT_KEYWORDS="~x86" sudo emerge =alsa-lib-1.0.2 \
=alsa-oss-1.0.2 =alsa-utils-1.0.2 alsamixergui
This will install all of the ALSA support software. Now we must modify the /etc/modules.d/alsa config file. Add the following lines to this file:
alias snd-card-0 YOUR-SOUND-CARD
alias snd-slot-0 snd-card-0
alias snd-pcm-oss dsp_map=2 adsp_map=2
After you have done this, run sudo /sbin/modules-update. It was also mentioned that you should create a .asoundrc file for each user that uses the sound card. We could not confirm that this was 100% necessary for our machine, but we added it anyway. Here was what was recommended to be put in that file:
pcm.nforce-hw {
type hw
card 0
}
pcm.!default {
type plug
slave.pcm "nforce"
}
pcm.nforce {
type dmix
ipc_key 1234
slave {
pcm "hw:0,2"
period_time 0
period_size 1024
buffer_size 32768
rate 48000
}
}
ctl.nforce-hw {
type hw
card 0
}
Finally, run sudo /sbin/rc-update add alsa default to get ALSA to run automatically on system startup. To start it up immediately, run sudo /etc/init.d/alsa start. After staring ALSA, run alsamixergui and ensure that all output channels are UNmuted. To test sound, run aplay $KDEDIR/share/sounds/pop.wav (assuming you have installed KDE).
Getting the DVD player to work
TODO: finish
Setting up the PVR card
Out of all of the tasks we performed, getting the PVR card to record was probably the most painful. In order to get the PVR to work, we must install a software package called IvyTV (though it's usually spelled ivtv in all the Gentoo packages). Download the source code, and then grab the unofficial patch for the 2.6.3 kernel. Apply this patch by doing the following:
- Unpack the source in your home directory (it should unpack to the
ivtvdirectory) - Save the patch file in your home directory as well
- Run the following command:
patch -p0 <ivtv-0.1.9-2.6-3-20040206.diff
After patching the source, run the following commands to download Hauppauge's Windows drivers, compile the IvyTV drivers, and install IvyTV utilities:
cd ivtv/utils
wget http://hauppauge.lightpath.net/software/pvr250/pvr250_17_21288.exe
./ivtvfwextract.pl pvr250_17_21288.exe
cd ../driver
make
sudo make install
cd ../utils
make
sudo cp ivtvfbctl ivtvplay mpegindex test_ioctl /usr/local/bin
Now we will create the module configuration file for IvyTV. Create the file /etc/modules.d/ivtv, and put the following in that file:
alias char-major-81 videodev
alias char-major-81-0 ivtv
alias char-major-61 lirc_i2c
options ivtv ivtv-debug=0 mpg_buffers=90
options tuner type=2
options msp3400 once=1 simple=1 debug=0
add below ivtv msp3400 saa7115 tuner
add above ivtv lirc_dev lirc_i2c
In order to allow IvyTV to be autoloaded into the kernel, add ivtv on a line by itself to /etc/modules.autoload.d/kernel-2.6. Once you've done all this, run sudo /sbin/update-modules, and to start it up, run sudo /sbin/modprobe ivtv.
Let's test it now. Make sure you have a video feed of some sort plugged in to your PVR card, then run the following commands:
ACCEPT_KEYWORDS="~x86" sudo emerge mplayer
sudo test_ioctl -u 0x3000
sudo test_ioctl -p 4
sudo test_ioctl -f width=720,height=480
sudo test_ioctl -v input=3,output=1
cat /dev/video0 > test.mpg
The last command should be run in a directory your user can write to, and on a filesystem that has a good amount of space - test.mpg will get big FAST (about 1 MB every 5 seconds)! Hit CTRL-C after about a minute, and run mplayer test.mpg to ensure that the video AND sound recorded. Congrats! You've gotten over the biggest hump.
Installing MythTV
We'll start with MythTV. Before we install it, though, there are a few other things we need to do first - in particular, we will create a new user called mythtv who will own all things MythTV-related. Run the commands below. Actually, before running the emerge commands below, run them with the -p switch - that way, you will see what will be installed, and if you even need to install it. In particular, if you already emerged KDE, you will not need to install qt - it's already installed! Anyway, run these commands:
sudo emerge qt corefonts ntp
sudo ln -s /dev/cdroms/cdrom0 /dev/dvd
sudo useradd -G users,audio,video,wheel mythtv
sudo passwd mythtv
sudo mkdir /home/mythtv
sudo cp /root/.asoundrc ~mythtv/.asoundrc
sudo chown mythtv:users -R /home/mythtv
Afterwards, be sure to set up the configuration for ntp in /etc/conf.d/ntp-client (this requires picking an NTP server to use - instructions can be found in the file itself), and to run sudo /sbin/rc-update add ntp default to allow ntp to run on startup.
Now, emerge MythTV! Depending on the speed of your machine, this may take a LONG time:
ACCEPT_KEYWORDS="~x86" emerge mythtv \
mythtv-themes mythbrowser mythdvd \
mythgallery mythmusic mythnews mythvideo \
mythweather mythweb
If you find that Gentoo tries to install linux-dvb, you will need to add the setting USE="-dvb" before emerge in the above command.
After this is done, complete the remaining steps in Sections 10 and 13 of our favorite MythTV setup Guide. You'll notice that we're skipping Sections 11 and 12, setting up LVM and LIRC. We felt the former was unnecessary, and the latter was not worth the trouble, but if you want your infrared remote control to work, you will need to get LIRC working. All we can say is, good luck, since at every turn we saw nothing but errors when trying to install LIRC software.
Configuring Freevo
Configuring freevo can take some time, and depending on your hardware be difficult. Since we used the Hauppauge 250 tuner card, we needed to use the correct drivers. Also, you need to know the correct settings for your setup. The best thing to do is to read through the configuration files and consult the website. Below are a few things we did that may help others to get their freevo working or understand the configuration aspect better.
To be able to watch and record tv, the first thing that needs to happen is to get the tvguide up and running. This only happens if you get the listings using XMLTV.
Using XMLTV
To get U.S. listings, you need to run tv_grab_na. The first step is to run tv_grab_na --configure and fill in your area code and channel preferences. To get actual listings, you need to need type the command tv_grab_na > /tmp/TV.xml. You need to make sure you put it in /tmp because Freevo looks in the that directory for your listings. If you run the command without specifying the --days option, tv_grab_na will generate 7 days of listings. It's probably best to write a cron job to keep grabbing the listings for you every couple of days.
Freevo's Config files
Freevo has 3 main config files, freevo.conf, local_conf.py, and freevo_config.py. freevo.conf is a short config file that keeps that keeps basic settings for the whole application. The main config file is freevo_config.py. Freevo's developers recommmend you do not change this file because freevo will look at your local_conf.py for your changes. If you make any changes to local_conf.py, you should make sure the changes match any variables in freevo.conf. freevo_config.py IS worth taking a look at because it contains a little more documentation about the config files. Freevo keeps the config files in different places based on your installation. For mine, freevo.conf and local_conf.py were both kept in the /etc/freevo directory. freevo_config.py was kept in /usr/share/freevo.
Here is a general how-to on how to configure freevo, along with recording info from freevo's site. The first thing you will have to do is to set up your directories to where you want your tv shows and movies stored. local_conf.py will have all the documentation you need for that. To get XMLTV working the first thing you need to do is set TV_CHANNELS correctly in local_conf.py. The key to getting this working correctly is to look at TV.xml. The format for the TV_CHANNELS variable is :
[('xmltv channel id', 'freevo display name', 'tv channel name'), ...]
Most of the documentation says that the the xmltv channel is usually a number. However, looking at my listings, the channel id was a URL. Here's a snapshot from TV.xml:
<channel id="C2wbbm.zap2it.com">
<display-name>2 WBBM</display-name>
<display-name>2</display-name>
<icon src="http://tvlistings2.zap2it.com/tms_network_logos/cbs_30.jpg" />
</channel>
Here is what my TV_CHANNELS ended up looking like:
TV_CHANNELS = [('C2wbbm.zap2it.com','CBS', '2'),
('C5wmaq.zap2it.com','NBC', '5'),
('C7wls.zap2it.com','ABC', '7'),
('C9wgn.zap2it.com','WGN', '9'),
('C11wttw.zap2it.com','PBS', '11'),
('C20wycc.zap2it.com','WYCC','20'),
('C26wciu.zap2it.com','WCIU','26'),
('C44wsns.zap2it.com','Telemundo!','44'),
('C32wfld.zap2it.com','FOX', '32'),
('C50wpwr.zap2it.com','UPN', '50'),
('3','Our station','3')]
The order in which you put the channels in this variable is the order in which you will see them in your tv guide. You should be able to see the tv guide option after you select the watching tv option in the main menu after you configure this variable. You can also set the xmltv variables in local_conf.py - in my file, XMLTV_GRABBER = tv_grab_na. It looks like along with using these settings and running:
/usr/bin/freevo tv_grab --help
will help you to get this set up automatically.
Watching TV
To watch tv, you need choose a plugin to handle your tv watching. At first I tried using the mplayer plugin, but I couldn't get it to work. I ran into this problem and I knew it was a matter of my local_config.py being outdated for the new version of mplayer. We had mplayer working outside of freevo, so we knew our pvr card worked with mplayer just fine. To try to get something to work I decided to use the ivtv_basic_tv plugin (which also uses mplayer). This plugin was actually an older plugin used for Hauppauage 250/350 cards. Since the mplayer plugin is used by default in freevo_config.py, you need to add the following lines to local_conf.py to remove the plugin and add the ivtv_basic_tv plugin:
plugin.remove('tv.mplayer')
plugin.activate('tv.ivtv_basic_tv')
Also for tv watching, you need to make sure the TV_SETTINGS and VCR_SETTINGS is set correctly, to do this just read the documentation in local_conf.py.
To use the ivtv plugins you need to adjust the ivtv settings in local_conf as well. Here are my settings:
IVTV_OPTIONS = {
'input' : 4,
'resolution' : '720x480',
'aspect' : 2,
'audio_bitmask' : 233,
'bframes' : 3,
'bitrate_mode' : 1,
'bitrate' : 4000000,
'bitrate_peak' : 4000000,
'dnr_mode' : 0,
'dnr_spatial' : 0,
'dnr_temporal' : 0,
'dnr_type' : 0,
'framerate' : 0,
'framespergop' : 15,
'gop_closure' : 1,
'pulldown' : 0,
'stream_type' : 10,
}
The only thing I changed was the input to 4 which is the standard tuner 0 input for the ivtv driver.
local_conf.py suggests to make additions to the FREQUENCY_TABLE variable. I didn't add any frequencies, since freevo looks up the frequencies based on either TV_SETTINGS or the chan_list and tv variables in freevo.conf. If you'd like to look at the frequency settings to add them to this table, you can go to the freq.py in /usr/lib/python2.3/site-packages/freevo/tv/freq.py .
The last thing you need to do is to go throught the mplayer section in local_conf, which takes some reading of mplayer's documentation. I left the majority of the variables the same, but I did set MPLAYER_AO_DEV to work with alsa and uncommented MPLAYER_ARGS.
A Small Bug
To watch tv through freevo, you go through the tv guide, highlight the program you want to watch, and hit enter. When I tried this at first, I got an error when MENU_SELECT crashed. I found out that the solution here. Basically there was a bug in the plugin's code. To fix it, I went to line 176 in ivtv_basic_tv.py and changed the following:
mpl = '--prio=%s %s -vo %s%s -fs %s -slave %s' % args
Taking a %s out will do the trick:
mpl = '--prio=%s %s -vo %s -fs %s -slave %s' % args
The plugin can be found in the /usr/lib/python2.3/site-packages/freevo/tv/plugins directory.
Recording Television
The first thing you need to do is to use the correct plugin. Since we're using the 250 card, we need the ivtv plugin for recording:
plugin.remove('tv.generic_record')
plugin_record = plugin.activate('tv.ivtv_record')
The second thing you need to make sure is that your DIR_RECORD is set so that freevo knows where to place your recorded shows.
Newer versions of freevo use a server application to record shows. The script record_server.py records shows even after you exit the main freevo application. If you are using record_server.py you need to uncomment the following lines from your local_conf file:
# if using the persitant record_server
RECORD_SCHEDULE = '%s/record_schedule.xml' % FREEVO_CACHEDIR
RECORD_SERVER_IP = 'localhost'
RECORD_SERVER_PORT = 18001
You need to make sure that the record server is running before you try to record. To start the record server from the command line, all you need it to run /usr/bin/freevo recordserver. You may want to set this up so that the record server comes up at boot time. Also, the main thing that will hinder recording is permissions! Make sure that you either run the recordserver as root or have the correct permissions to the files that it needs. To find out the correct files, try running record server as a normal user and looking in the log files if recording gives you an error.
The log files are supposed to be kept in /var/log/freevo, but mine showed up in the /tmp directory.
To actually record a show, you need to go through the tv guide and highlight the show, then press F6.
DVD playback in Freevo
One thing to note is that Freevo uses Xine for DVD playback. The only thing we needed to do to get this to work was to use a region set tool. When Xine tried to play a DVD, it took 15 minutes to being playback. The reason was that the dvd region was not set correctly. Each encrypted dvd has a region code (i.e. 1 for the US). To fix the problem we downloaded a region set tool. To use the tool all we needed was a DVD. To read more about this, you can visit this faq.