Difference between revisions of "Mythtv:Remove Commercials"

From LinuxMCE
Jump to: navigation, search
(Whats Required)
(CLI Example)
Line 88: Line 88:
 
  %DIR% %FILE%
 
  %DIR% %FILE%
 
It can be run from command line on any file, but works great as User Job 2:
 
It can be run from command line on any file, but works great as User Job 2:
  /usr/local/bin/removecommercials.sh /home/public/data/videos/tv_shows_1 2135_200809040000.mpg
+
  /usr/local/bin/removecommercials.sh /home/public/data/videos/tv_shows_1 2135_20080904010000.mpg
  
 
== Setting Up The User Job for Automagic Use ==
 
== Setting Up The User Job for Automagic Use ==

Revision as of 17:29, 9 September 2008


Remove Commercials From Your MythTV Recordings

This is a detailed tutorial on how to remove the commercials from your MythTV recordings. I have tested it, and using some of the information from this wiki Mythtv:Skipping_Commercials and provided a method to do this automatically, and reduce the size of your recordings.

Whats Required

1. MythTV configured and working in LMCE

2. Script to flag commercials, generate cutlist, and transcode out the commercials.

3. Changes must be made on all Backends with a tuner card (I have an MD with tuner cards, so the script had to be copied to the MD's /usr/local/bin folder)

The Script

Here is the web link to where this information was acquired. MythTV Wiki

#!/bin/sh
VIDEODIR=$1
FILENAME=$2
# Sanity checking, to make sure everything is in order.
if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
        echo "Usage: $0 <VideoDirectory> <FileName>"
        exit 5
fi
if [ ! -f "$VIDEODIR/$FILENAME" ]; then
        echo "File does not exist: $VIDEODIR/$FILENAME"
        exit 6
fi
# The meat of the script. Flag commercials, copy the flagged commercials to
# the cutlist, and transcode the video to remove the commercials from the
# file.
mythcommflag -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -gt 126 ]; then
        echo "Commercial flagging failed for ${FILENAME} with error $ERROR"
        exit $ERROR
fi
mythcommflag --gencutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -ne 0 ]; then
        echo "Copying cutlist failed for ${FILENAME} with error $ERROR"
        exit $ERROR
fi
mythtranscode --honorcutlist --showprogress -i $VIDEODIR/$FILENAME -o $VIDEODIR/$FILENAME.tmp
ERROR=$?
if [ $ERROR -ne 0 ]; then
        echo "Transcoding failed for ${FILENAME} with error $ERROR"
        exit $ERROR
fi
mv $VIDEODIR/$FILENAME $VIDEODIR/$FILENAME.old
mv $VIDEODIR/$FILENAME.tmp $VIDEODIR/$FILENAME
mythcommflag -f $VIDEODIR/${FILENAME} --rebuild
ERROR=$?
if [ $ERROR -ne 0 ]; then
        echo "Rebuilding seek list failed for ${FILENAME} with error $ERROR"
        exit $ERROR
fi
mythcommflag --clearcutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -eq 0 ]; then
        # Fix the database entry for the file
        cat << EOF | mysql mythconverg
UPDATE 
        recorded
SET
        cutlist = 0,
        filesize = $(ls -l $VIDEODIR/$FILENAME | awk '{print $5}') 
WHERE
        basename = '$FILENAME';
EOF
        exit 0
else
        echo "Clearing cutlist failed for ${FILENAME} with error $ERROR"
        rm /usr/video/$FILENAME.tmp
        exit $ERROR
fi

Save this file in /usr/local/bin as removecommercials.sh

sudo vi /usr/local/bin/removecommercials.sh  (and paste)

And make it executable

chmod a+x /usr/local/bin/removecommercials.sh


CLI Example

Now the script requires 2 arguments

%DIR% %FILE%

It can be run from command line on any file, but works great as User Job 2:

/usr/local/bin/removecommercials.sh /home/public/data/videos/tv_shows_1 2135_20080904010000.mpg

Setting Up The User Job for Automagic Use

This can be done easily in 2 ways

1. Use the "Computing" LMCE menu item and run myhthtv-setup (or from the cli if you prefer as root)

2. Use MythWeb (The Easiest)


Method 1 - Using MythTV-Setup

Now from the mythtv-setup option, Go to:

General > and navigate to the User Jobs portion.

Insure to 'tick' 'Allow User Job 2", and in the line for User Job 2 add the following:

Replace "User Job 2" with "Remove Commercials"
Job line "/usr/local/bin/removecommercials.sh %DIR% %FILE%

This should be located directly below the Save Recording to Pluto DB job (User Job 1)

NOTE!!! It is very important to add this job as Job 2, as Job 1 is always overwritten by LMCE to the Save Recording Job.


Method 2 - Using Mythweb (Easiest)

Go to MythWeb (Note here that I use /usr/pluto/bin to run the script, this is not required)

Move your mouse to "Settings" and click "MythTV Settings Table"

Scroll to the bottom, to where you can see the User Job Entries

Mythsettings.png

Under "UserJob2" enter the line

/usr/local/bin/removecommercials.sh %DIR% %FILE%

Under "UserJobDesc2" enter the text

Remove Commercials

Now at the bottom click "Save"

That's it your done!

Usage

The easiest way to use this function, and schedule your recordings is through MythWeb

While scheduling your recordings, make sure to put a check in the box next to your new job: (See image)

Mythrecord.png

This can also be done while scheduling the recordings through MythTV's Guide feature, when you choose the show to record, go into the "Post recording Options" and Choose "Run Remove Commercials"

But I personally think Mythweb is the best way to do your scheduling.

Warnings

The script does not delete the original recording. It renames it in the working directory to 2135_200809040000.mpg.old.

After you verify and are happy that the commercial removal went as expected, (its about 98% accurate) then go back through and delete the .old file to free up hard drive space!

The End Result

This can very effectively remove the commercials from your favorite shows, and at 1/3 the size of ripping a set of dvd's of your favorite show, it can greatly reduce the cost of storage space. The new file is also reduced in size anywhere from 100MB to 400MB for SD, and as much as 1.5GB of HD recordings, so this will also help reduce the cost of storage.

And did I forget to mention, that now all those pesky, money grubbing commercials are now gone, and your show is no longer interrupted?!?!?!

I hope this helps someone. It definitely makes for a better viewing experience in LMCE/MythTV terms.

Regards,

Seth User:Seth