Transcode

For some reason, my MythTV setup doesn't transcode properly. I don't know if it's a bug in a particular version of 'transcode' or what, so I wrote my own little script that mimics transcode's functionality. It's not the cleanest code, but it works.

$ ./transcode.pl 
Select the title of the series:
   0: Bull Riding
   1: Heroes
   2: Nova
   3: Pushing Daisies
   4: Saturday Night Live
: 3
 
Select the episode of the series:
   0: Bzzzzzzzzz!
   1: Circus Circus
   2: Bad Habits
   3: Frescorts
   4: Dim Sum Lose Some
: 3
 
Series: Pushing Daisies
Episode: Frescorts
 
Source: /data/mythtv/recordings/1131_20081022190000.mpg
Cutlist: --honorcutlist "31792-42767 69879-82054 96177-107176 122346-137948 162816-179488"
Destination: /data/mythtv/videos/temp/pushingdaisies.frescorts.avi
 
$ /usr/bin/mythtranscode -m -i /data/mythtv/recordings/1131_20081022190000.mpg --honorcutlist "31792-42767 69879-82054 96177-107176 122346-137948 162816-179488" -o /data/mythtv/videos/temp/pushingdaisies.frescorts.mpg
$ /usr/bin/ffmpeg -i /data/mythtv/videos/temp/pushingdaisies.frescorts.mpg -s 1280x720 -deinterlace -vcodec mpeg4 -qscale 6 -acodec copy /data/mythtv/videos/temp/pushingdaisies.frescorts.avi
$ rm -f /data/mythtv/videos/temp/pushingdaisies.frescorts.mpg*
 
Continue [y/N]: y
#!/usr/bin/perl
 
my $sourcepath = "/data/mythtv/recordings/";
my $destinationpath = "/data/mythtv/videos/temp/";
my $dbuser = "whoever";
my $dbpass = "whatever";
 
# CONNECT
 
use DBD::mysql;
$dsn = 'dbi:mysql:mythconverg:localhost:3306';
my $dbn = DBI->connect($dsn, $dbuser, $dbpass)
        or die "Can't connect to the DB: $DBI::errstr\n";
 
# SERIES
 
my $query = "select distinct title from recorded order by title";
my $sth = $dbn->prepare($query);
$sth->execute();
print "Select the title of the series:\n";
my @seriesarray;
my $i=0;
while (my($title) = $sth->fetchrow_array()) {
        push(@seriesarray,$title);
        print "   $i: @seriesarray[-1]\n";
        $i += 1;
}
print ": ";
my $series = <>;
 
# EPISODE
 
$query = "select distinct subtitle, programid from recorded where title like '".mysqlstr(@seriesarray[$series])."' order by programid";
$sth = $dbn->prepare($query);
$sth->execute();
print "\nSelect the episode of the series:\n";
my @episodearray;
my $j=0;
while (my($subtitle) = $sth->fetchrow_array()) {
        push(@episodearray,$subtitle);
        print "   $j: $episodearray[-1]\n";
        $j += 1;
}
print ": ";
my $episode = <>;
 
# SOURCE
 
$query = "select distinct basename, commflagged from recorded where title like '".mysqlstr(@seriesarray[$series])."' and subtitle like '".mysqlstr(@episodearray[$episode])."'";
$sth = $dbn->prepare($query);
$sth->execute();
my($basename, $commflagged) = $sth->fetchrow_array();
my $source = $sourcepath.$basename;
my $cutlist = "";
if ($commflagged eq "1") {
        my $cuts = `mythcommflag -f $source --getskiplist | tail -n 1 | awk '{print \$4}' | sed 's/,/ /g'`;
        chomp($cuts);
        $cutlist = "--honorcutlist \"$cuts\"";
}
 
# DESTINATION
 
my $seriesname = cleanstr(@seriesarray[$series]);
my $episodename = cleanstr(@episodearray[$episode]);
my $temp = $destinationpath.$seriesname.".".$episodename.".mpg";
my $destination = $destinationpath.$seriesname.".".$episodename.".avi";
 
# CONFIRMATION
 
print "\n";
print "Series: ".@seriesarray[$series]."\n";
print "Episode: ".@episodearray[$episode]."\n\n";
print "Source: $source\n";
print "Cutlist: $cutlist\n";
print "Destination: $destination\n\n";
my $cmd1 = "/usr/bin/mythtranscode -m -i $source $cutlist -o $temp";
#my $cmd2 = "/usr/bin/ffmpeg -i $temp -s 1280x720 -deinterlace -vcodec mpeg4 -qscale 6 -ac 2 -acodec ac3 -ab 256k $destination";
my $cmd2 = "/usr/bin/ffmpeg -i $temp -s 1280x720 -deinterlace -vcodec mpeg4 -qscale 6 -acodec copy $destination";
my $cmd3 = "rm -f $temp*";
print "\$ $cmd1\n";
print "\$ $cmd2\n";
print "\$ $cmd3\n\n";
print "Continue [y/N]: ";
my $go = <>;
 
# DO IT
 
chomp($go);
if ($go eq "y") {
        my $cmd = "$cmd1 && $cmd2 && $cmd3";
        exec $cmd;
} else {
        print "Aborted!\n";
}
 
sub mysqlstr {
        my $str = shift;
        $str =~ s/'/''/g;
        return $str;
}
 
sub cleantime {
        my $str = shift;
        $str =~ s/[ \-\:]//g;
        return $str;
}
 
sub cleanstr {
        my $str = shift;
        $str = lc($str);
        #$str =~ s/ //g;
        $str =~ s/[ \;\-,\.\':]//g;
        return $str;
}
mythtv_scripts.txt · Last modified: 2009/02/01 20:29 UTC by dustin