PVR Update

In anticipation of TV shows coming back on, I’ve been tweaking my PVR scripts. These record shows from the digital airwaves right onto my computer. I’ve separated the script into two parts: recording and encoding. Each is a simple one line shell script that can be called easily from the command line or from a cron. The record.sh script is:

/usr/bin/mencoder dvb://$1 -ovc copy -oac copy -o "$2.mpeg" -endpos $3

All this does is copy the video and audio streams directly to the disk. The three parameters are  the station name, as stated in ~/.mplayer/channels.conf, the filename and the end position. This end position can be the number or seconds to record, or a time format of hh:mm:ss. This makes recording fairly simple within the cron.

The encode.sh script contains:

/usr/bin/mencoder -vf scale=640:-2 -ovc xvid -xvidencopts bitrate=1700:threads=2 \
 -oac copy "$1" -o "$1.avi"

This, slightly more complex use of mencoder, will scale the video to 640 wide, the height calculated to keep the aspect ratio. The video is encoded into xvid at 1700kbps using 2 threads. To speed up the encoding process, the audio is not re-encoded, but copied as is.

You will need to play with the number of xvid threads to find the best fps. I have a dual-core and it encodes the fastest with 2 threads. It does need to be an integer, and most dual-cores will work best at 2.

Then, two lines are required in the cron to record and encode the program:

59 19 * * 1 /dvr/record.sh WAGTNBC /dvr/shows/heroes 01:03:00
05 20 * * 1 /dvr/encode.sh /dvr/shows/heroes.mpeg