[mythtv-users] Auto-transcode to x264 and update MythTV database along the way

Kris B. krisbee at krisbee.com
Fri Dec 9 03:54:02 UTC 2011


On Thu, Dec 8, 2011, at 05:45 PM, Tom Hayward wrote:
> On Thu, Dec 8, 2011 at 16:58, Robert Waldner <waldner at waldner.priv.at>
> wrote:
> >
> > Aloha,
> >
> > after looking through Google search results for quite some time, I
> >  can't find exactly what I'm looking for. Now, before I write it myself
> >  ... maybe someone already did, and I just didn't use the right keywords
> >  when searching.
> >
> > What I'm looking for is a script that:
> >  - does the mythcommflag dance
> >  - runs HandBrakeCLI to transcode to x264 in a way that won't actually
> >   *cut* the commercials, just flag start/end with chapter markers
> >  - puts the result in an MKV container
> >  - in a prettified directory structure (like Title/Episode)
> >  - deletes the original file
> >  - updates the MythTV DB so that it points to the MKV file instead of
> >   the original
> >  - while retaining the original meta-data
> >
> > Any hints?
>
This is not my script, but from the mythtv channel for the roku, it will
not put it in a .mkv, but does in an mp4, and also does not move it in a
different directory.. however it will update myth to point at the
correct file, the commercial skip DOES work, and does delete the
original file.  I think the only tweak I did is that to rerun for the
seektable to work in myth.  Just make sure that when you set to run this
user job that commercial flagging is also selected (done automatically
for any of my programs)... I also had posted on here my mods that
actually hard cut the commercials.:

[krisbee2010 at localhost ~]$ cat /usr/local/bin/mythrokuencode.sh 
#!/bin/bash

#convert mpeg file to mp4 using handbrakecli
MYTHDIR=$1
MPGFILE=$2

# Should try and get these from settings.php, but for now...
DATABASEUSER=mythtv
DATABASEPASSWORD=mythtv

LOGFILE="/var/log/mythtv/rokuencode.log"
 
newbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'`
newname="$MYTHDIR/$newbname.mp4"

echo "Roku Encode $MPGFILE to $newname, details in $LOGFILE" >> $LOGFILE

date=`date`
echo "$newbname:$date Encoding" >> $LOGFILE
#/usr/bin/HandBrakeCLI -i $1/$2 -o $newname -e x264 -b 1500 -E faac -B
256 -R 48 -w 720
#/usr/bin/HandBrakeCLI -i $MYTHDIR/$MPGFILE -o $newname -e x264 -r 29.97
-b 1500 -E faac -B 256 -R 48 --decomb >> $LOGFILE 2>&1
#/usr/bin/HandBrakeCLI --preset='iPhone & iPod Touch' -i
$MYTHDIR/$MPGFILE -o $newname >> $LOGFILE 2>&1
/usr/bin/HandBrakeCLI --preset='iPhone & iPod Touch' -i
$MYTHDIR/$MPGFILE -o $newname 

date=`date`
echo "$newbname:$date Previews" >> $LOGFILE
#Mythtv seems to have problems with keyframes in mp4s, so make previews
with ffmpeg
   ffmpeg -loglevel quiet -ss 34 -vframes 1 -i $newname -y -f image2 
   $MYTHDIR/$newbname.mp4.png >> $LOGFILE 2>&1
   ffmpeg -loglevel quiet -ss 34 -vframes 1 -i $newname -y -f image2 -s
   100x75 $MYTHDIR/$newbname.mp4.64.100x75.png >> $LOGFILE 2>&1
   ffmpeg -loglevel quiet -ss 34 -vframes 1 -i $newname -y -f image2 -s
   320x240 $MYTHDIR/$newbname.mp4.64.320x240.png >> $LOGFILE 2>&1
#ffmpeg -loglevel quiet -ss 34 -vframes 1 -i $newname -y -f image2 -s
100x75 $MYTHDIR/$newbname.jpg >> $LOGFILE 2>&1

date=`date`
echo "$newbname:$date Database/remove" >> $LOGFILE
# remove the orignal mpg and update the db to point to the mp4
NEWFILESIZE=`du -b "$newname" | cut -f1`
echo "UPDATE recorded SET
basename='$newbname.mp4',filesize='$NEWFILESIZE',transcoded='1' WHERE
basename='$2';" > /tmp/update-database.sql
mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg <
/tmp/update-database.sql
rm $MYTHDIR/$MPGFILE

echo "Updating Seektable so you can fast forward in Myth" >> $LOGFILE
mythcommflag --rebuild --file $newname

date=`date`
echo "$newbname:$date Complete" >> $LOGFILE
echo "" >> $LOGFILE



-- 
  Kris B.
  krisbee at krisbee.com



More information about the mythtv-users mailing list