Streaming General Conference from MythTV

Every 6 months, the Church of Jesus Christ of Latter-day Saints broadcasts on television a series of meetings called General Conference.  There are usually 6 meetings, each 2 hours long, each meeting consisting primarily of talks by about 6 people.  On General Conference weekends, members of the Church watch the conference instead of attending local meetings.

I like to use MythTV to record the public sessions from KSL, a local TV station.  That way, I get a pristine, high definition picture that I can review anytime I like.

Two of the meetings are on Saturday.  During the Saturday meetings, I prefer to multitask while listening to conference.  I want my wireless laptop to play the audio and a miniature version of the video.  I finally figured out how to do that.

I started with the directions on parker1.co.uk.  That page describes how to use VideoLAN to stream a video even as it’s being created.  Unfortunately, those directions seem to be out of date, as is the mythlink script the page links to.   So here is my version of the mythlink script (with the database password replaced with ‘fakepw’):

#!/bin/sh

# mythlink.sh - Symlinks mythtv files to more readable versions
# by Dale Gass

if [ ! -d /tv/links ]; then mkdir /tv/links; fi
rm -f /tv/links/*

echo "Done RM"
mysql -umythtv -pfakepw mythconverg -B --exec "select chanid,starttime,endtime,title,subtitle from recorded;" >/tmp/mythlink.$$
perl -w -e '
        my $mythpath= "/tv";
        my $altpath= "/tv/links";
        if (!-d $altpath) {
                mkdir $altpath or die "Failed to make directory: $altpath\n";
        }
        <>;
        while (<>) {
                chomp;
                my ($chanid,$start,$end,$title,$subtitle) = split /\t/;
                $start =~ s/[^0-9]//g;
                $end =~ s/[^0-9]//g;
                $subtitle = "" if(!defined $subtitle);
                my $ofn = "${chanid}_${start}.mpg";
                do { print "Skipping $mythpath/$ofn\n"; next } unless -e "$mythpath/$ofn";
                $start =~ /^(............)/;
                my $nfn = "$1_${title}";
                if ($subtitle) {$nfn="${nfn}__${subtitle}"}
                $nfn =~ s/ /_/g;
                $nfn =~ s/&/+/g;
                $nfn =~ s/[^+0-9a-zA-Z_-]+/_/g;
                $nfn = "${nfn}.mpg";
                print "Creating $nfn\n";
                unlink "$altpath/$nfn" if(-e "$altpath/$nfn");
                symlink "$mythpath/$ofn", "$altpath/$nfn" or die "Failed to create symlink $altpath/$nfn: $!";
        }
' /tmp/mythlink.$$
rm /tmp/mythlink.$$

This handy script generates links to make it easy to find recorded TV programs on the filesystem. After running the script, I started a VLC streaming server like this:

vlc 200904041400_LDS_General_Conference.mpg --sout \
'#transcode{vcodec=mp4v,vb=2048,scale=0.25,acodec=mp3,ab=128,channels=2}:std{access=http,mux=ts,dst=:8081}'

I learned what options are available from the VLC streaming documentation.  The command I used creates a 2 megabit per second streaming server using the MPEG-4 and MP3 codecs, with the video scaled from high definition (1920×1080) to 480×270. Then I launched the client on my laptop:

vlc http://tiger:8081

This worked very well. Both the video and audio were very clean and never stalled.  The MythTV server has an AMD 5200+, which is more than fast enough to simultaneously record the high definition stream to a hard drive, play it back with scaling, transcode down to 480×270, and send the transcoded stream to multiple clients.

Of course, this will all be much easier when MythWeb gains the ability to generate Flash videos.

12 Cents Per Gigabyte

640 GB, 7200 RPM, 32 MB cache, 5 year warranty: $75 ($0.12/GB), free shipping.  It’s almost too good to be true.

Still, the best drive for MythTV is Western Digital’s low power series.  I’ve been using the 750GB GP model with MythTV for about a year now and it has been silent and completely reliable the whole time.  It contains an XFS filesystem, which probably helps quite a bit when recording 6 GB/hr (full HD resolution).  The MySQL database that MythTV relies on happens to be on another drive, but I imagine it would be fine to put the database on the same drive.