Stuart's Perl DVR Files

dvr.pl
The main perl script which is in control of everything. Note you will need to change the file extension to .pl.

dvrcommands.pl
Most of the functions that read the schedule file. Note you will need to change the file extension to .pl.

record.pl
This is called by dvr.pl to start the recording. Note you will need to change the file extension to .pl.

dvr.conf
Configure various options to do with recording - can specify recording program location and command line options here

schedule.txt
An example of the schedule file. Examples of recording a programme at the same time every weekday, every Monday and archiving a programme.

Digital Video Recording
(with a bit of Perl and mencoder)

NOTE: This page is currently under construction so may not make a great deal of sense. I just wanted to get something up so that other people might benefit from my scripts. These scripts are also very messy and are in no way meant to be wonderful - they do the job that was required of them.

In May 2003 I decided that I had heard about digital video recorders for long enough and I wanted one. I had heard that TiVo required a monthly subscription and I wondered how much information they would store about me and my viewing habits - boring as they are. So I decided to build one myself to see if it was possible.

The Hardware

I looked around for a small, quiet PC that would be able to sit in my living room next to the TV. I found the fairly new (at that point) Shuttle XPC that seemed just the ticket. I bought a SS40G and installed a Hauppage TV card that I had bought for £35 the year before. After initial problems installing RedHat 8.0, I eventually managed to get it all working.

Now I needed some software. I tried using MythTV but it seemed to disagree with my setup so I turned to Freevo (see the Freevo Installation HOWTO). I've had some problems; I am unable to get the sound directly from the TV card and the recording deamon didn't work. To solve the audio problem I have had to use a short cable from the TV card to the line-in of the computer - not brilliant but it works. I'm not sure why the Freevo recording deamon didn't work but Freevo was able to store a list of scheduled recordings in a file so I decided to work from that. Mencoder seemed to be a good choice for recording programmes as it comes with MPlayer (a media player for Linux). After some effort I managed to find a suitable list of command line options that worked so I just needed a method of calling it which didn't need me to be there.

A Perl DVR Daemon

I turned to Perl, as usual, when I can't think of anything more appropriate. I created a Perl script which forks itself off into the background and every minute wakes up to check if it should be doing anything. This reads from the Freevo scheduled recording file and starts/stops recordings. I made a web-based (over my home network) interface to the recording program so that I could add to the schedule from anywhere in my house. At this point I slightly modified the Freevo schedule file so that I could do some things which were a bit more useful. For instance, I might like to record a programme which is on at the same time every week or even every weekday (such as The Simpsons on BBC2 at 6pm). I also made it possible to choose whether the programmes should be archived (i.e. saved with a time tag in the title) or could be overwritten - as I might want to store all episodes of Rough Science but not save every weather bulletin. This seems to work very well and eventually I plan to add a fuzzy option so that it can adjust to changes in the schedule e.g. for programmes such as the Sky at Night which happen whenever the channel controller has a spare slot.

Installation

Make sure that you have mencoder installed if you want to use my scripts straight away. You can also adapt this to be used with any other command line driven video recorder by editing dvr.conf.

  1. download all the files listed above
  2. change the file endings of dvr.txt, dvrcommands.txt and record.txt to .pl
  3. on unix you should change the permissions of the .pl files so that they are executable. e.g.
    chmod 755 *.pl
  4. edit the file dvr.conf with your favourite text editor (e.g. pico or emacs). Change the location of the schedule file to the current location of schedule.txt (you downloaded it a couple of steps before). Specify the location of mplayer on your system for the play command - this lets the perl script kill it if it is already running so that you can record from the TV card. Set the record option to be the location of mencoder on your system. Save the file and exit
  5. on the command line (in the same directory) type perl dvr.pl start

The program will then fork off into the background waking itself up every minute to check if it should be recording.

Ideas for the future