MythTV and the UK Digital Switchover

We had part one of the Digital Switchover in our area on Wednesday, so I finally had to bite the bullet and do a proper DVB channel re-scan on my MythTV box.

When I first set up DVB on my Myth box (previously I’d only used an S-Video capture card to record from my Sky satellite box) I had a ‘mare of a job setting the channels up.  Admittedly that was years ago now, and MythTV’s scanning has moved on since then (but the channel editor’s still a bit of a PITA), but it scared me off doing scanning from within Myth till just now.

Instead, I did the occasional scan with dvb-appsscandvb (with MythTV stopped) to generate a channels.conf file, then I had a small perl script which would look in that for channels that I had in my Myth SQL database that were on the frequencies used by my local transmitter, then generate the SQL updates and correct the channels, frequencies and channel numbers directly.

With the wholesale changes about to happen, that wasn’t going to cut the mustard, so a full scan was on the cards.  This is, to be honest, what pretty much everyone on the mailing list was recommending anyway.

Before the change, I did a test scan (after backing up the database!) to see what sort of things would happen.  It didn’t go well:  a full scan from MythTV  picked up loads of superfluous copies of channels that could be just about seen from other transmitters.

I restored the database, and instead did a scan on existing transports, a Myth option that only scans the frequencies it already knows about (so correctly limiting it to the local transmitter).

That seemed to work out OK, so I tidied up the new channels it had added and waited for Wednesday.

Anticipating problems, I wrote a couple of small perl scripts to store & restore some important channel information (such as my own name for them as opposed to the callsign that is transmitted as an ID, and the xmltvid which is used to link to Radio Times TV listings).

After some serious playing after the changeover, what I ended up doing was this:

Dump the channel data I wanted to keep:

#!/usr/bin/perl -w
use DBI;
my $dsn = 'DBI:mysql:mythconverg:hostname';
my %dbattr = ( PrintError => 1, RaiseError => 0 );
my $dbh;
$dbh = DBI->connect($dsn, 'user', 'password', \%dbattr);
$dbh->{RaiseError} = 1  if defined($dbh);
    my $querystr = qq`SELECT channum,callsign,name,icon,xmltvid,useonairguide,visible,commmethod FROM channel WHERE sourceid=1`;
    my $query = $dbh->prepare( $querystr );
    while (my $hashref = $query->fetchrow_hashref())
        print join("\t", (
                $hashref->{commmethod} ) )
            . "\n";

Note that this updates items for sourceid=1, which is my Freeview set. If you use this, you’d have to check which sourceid you have DVB on.

Update the local transmitter frequency table to remove the now defunct channel and add the new mux (from data gleaned from the excellent resource UKFree.TV).

Then I stopped Myth, and did a channel scan:

scandvb ~/etc/dvb-t-uk-BluebellHill > /tmp/channels.conf

I found it was moving on to a non-existent channel and a duplicate (slightly different frequency) for some reason (I think channels can have hints in them that other frequencies should be checked), so I just deleted the duplicate channel entries from the bottom of the file.

In mythtvsetup, went to the channel editor, selected Freeview and deleted all those channels (not my Sky ones), then chose a “scan from channels.conf”, which reads the manual scan file above, and checks each of the channels listed in it).

I then quit out and restored the custom data I’d kept back:

#!/usr/bin/perl -w
my $nums = 0;
if ($ARGV[0] and $ARGV[0] eq '-n')
    $nums = 1;
open( CHANNELS, "<$ARGV[0]" ) or die "failed to find channel file '$ARGV[0]'\n";
while (defined( my $channel = <CHANNELS> ))
    my @data = split("\t",$channel);
    my %data = (
        channum         => $data[0],
        callsign        => $data[1],
        name            => $data[2],
        icon            => $data[3],
        xmltvid         => $data[4],
        useonairguide   => $data[5],
        visible         => $data[6],
        commmethod      => $data[7],
    my $channum = ($nums ? qq`,channum=$data{channum}` : '');
    print qq`UPDATE channel SET name="$data{name}",icon="$data{icon}",xmltvid="$data{xmltvid}",useonairguide="$data{useonairguide}",visible="$data{visible}",commmethod="$data{commmethod}"$channum WHERE sourceid=1 AND callsign="$data{callsign}";\n`;

Then finally back into mythtvsetup to tart up new channels it had found (mostly disabling non-free & grot ones it had added).

I restarted Myth, and lo-and-behold, it was all working!  All that needed to be done was another TV-listings fetch, to refresh the now-deleted listings for the old channel entries.


Roll on next fortnight when the final change happens, and all the broadcast powers are finally maxed.


About fnx

PSN: the_phoenix
This entry was posted in Software, Tech and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *