Difference between revisions of "Mythtv:Remove Commercials"

From LinuxMCE
Jump to: navigation, search
(Remove Commercials From Your MythTV Recordings)
m (Method 1 - Using MythTV-Setup)
 
(6 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
2. Script to flag commercials, generate cutlist, and transcode out the commercials.
 
2. Script to flag commercials, generate cutlist, and transcode out the commercials.
  
3. Changes must be made on all Backend 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)
+
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 ==
 
== The Script ==
Line 86: Line 85:
  
 
== CLI Example ==
 
== CLI Example ==
Now the script requires 2 arguments  
+
Now the script requires 2 arguments - It averages from 15 to 25 minutes to complete, depending on available resources, and size of recording.
 
  %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 ==
Line 95: Line 94:
 
This can be done easily in 2 ways
 
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)
+
1. Use the "Computing" LMCE menu item and run mythtv-setup (or from the cli if you prefer as root)
  
 
2. Use [http://dcerouter/mythweb MythWeb] (The Easiest)
 
2. Use [http://dcerouter/mythweb MythWeb] (The Easiest)
 
  
 
== Method 1 - Using MythTV-Setup ==
 
== Method 1 - Using MythTV-Setup ==
Line 107: Line 105:
  
 
Insure to 'tick' 'Allow User Job 2", and in the line for User Job 2 add the following:
 
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"
+
  Replace "User Job 2" with "Remove Commercials" (No quotes of course)
  Job line "/usr/local/bin/removecommercials.sh %DIR% %FILE%
+
  Job line "/usr/local/bin/removecommercials.sh %DIR% %FILE%" (No quotes of course)
 
This should be located directly below the Save Recording to Pluto DB job (User Job 1)
 
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.
 
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) ==
 
== Method 2 - Using Mythweb (Easiest) ==
Line 122: Line 119:
 
Scroll to the bottom, to where you can see the User Job Entries
 
Scroll to the bottom, to where you can see the User Job Entries
  
[[Image:Mythsettings.png]]
+
[[Image:Mythweb.png]]
  
 
Under "UserJob2" enter the line
 
Under "UserJob2" enter the line
Line 146: Line 143:
 
== Warnings ==
 
== Warnings ==
  
The script does not delete the original recording. It renames it in the working directory to 2135_200809040000.mpg.old.
+
The script does not delete the original recording. It renames it in the working directory to 2135_20080904010000.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!
 
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!

Latest revision as of 17:54, 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 - It averages from 15 to 25 minutes to complete, depending on available resources, and size of recording.

%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 mythtv-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" (No quotes of course)
Job line "/usr/local/bin/removecommercials.sh %DIR% %FILE%" (No quotes of course)

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

Mythweb.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_20080904010000.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