Difference between revisions of "Script - commercialremover"
Line 3: | Line 3: | ||
{{Warning box|This behavior is not supported within the mythutil/mythtranscode programs themselves as the commercial detector is not considered sufficiently accurate to permanently remove sections of video without a manual confirmation.}} | {{Warning box|This behavior is not supported within the mythutil/mythtranscode programs themselves as the commercial detector is not considered sufficiently accurate to permanently remove sections of video without a manual confirmation.}} | ||
+ | |||
In order to run the script as a user job, add the following command as a user job in your backend setup. | In order to run the script as a user job, add the following command as a user job in your backend setup. | ||
Line 9: | Line 10: | ||
{{Note box|Be sure that /etc/mythtv/mysql.txt has the required information to edit the database. Also, be sure that it can be read and that the user can edit /tmp/ folder, which will be used to store logs. Be aware, in its current state, the script will overwrite the original recording, which may not always work correctly.}} | {{Note box|Be sure that /etc/mythtv/mysql.txt has the required information to edit the database. Also, be sure that it can be read and that the user can edit /tmp/ folder, which will be used to store logs. Be aware, in its current state, the script will overwrite the original recording, which may not always work correctly.}} | ||
+ | |||
The following script can be setup as a User Job to automatically flag and remove commercials from a recording. This script code was updated 11/21/2013 to work with MythTV 0.27. It should still work with 0.26 as well. | The following script can be setup as a User Job to automatically flag and remove commercials from a recording. This script code was updated 11/21/2013 to work with MythTV 0.27. It should still work with 0.26 as well. |
Revision as of 06:47, 22 November 2013
This script was started based upon the old script, which was needed as part of the MythGrid plugin development. It was necessary to change it so significantly to get the required behavior, that it seemed cleaner to post it as a new script.
Warning: This behavior is not supported within the mythutil/mythtranscode programs themselves as the commercial detector is not considered sufficiently accurate to permanently remove sections of video without a manual confirmation.
In order to run the script as a user job, add the following command as a user job in your backend setup.
commercialremover.sh %DIR% %FILE% %CHANID% %STARTTIMEUTC%
Note: Be sure that /etc/mythtv/mysql.txt has the required information to edit the database. Also, be sure that it can be read and that the user can edit /tmp/ folder, which will be used to store logs. Be aware, in its current state, the script will overwrite the original recording, which may not always work correctly.
The following script can be setup as a User Job to automatically flag and remove commercials from a recording. This script code was updated 11/21/2013 to work with MythTV 0.27. It should still work with 0.26 as well.
#!/bin/sh ##### commercialremover.sh Script for MythTV, updated 2013/11/21 ### ## Made for MythTV 0.26 also tested against 0.27, by jmw for MythGrid ## https://sourceforge.net/projects/mythgrid/ ## ## This script requires the User Job to pass additional arguments under MythTV 0.26 or higher ## User job command: ## ‘commercialremover.sh %DIR% %FILE% %CHANID% %STARTTIMEUTC%' ### ##### VIDEODIR=$1 FILENAME=$2 CHAN=$3 START=$4 # Sanity checking, to make sure everything is in order. Modified to check $CHAN and $START for MythTV 0.25 or higher support if [ -z "$VIDEODIR" -o -z "$FILENAME" -o -z "$CHAN" -o -z "$START" ]; then echo "Usage: $0 <VideoDirectory> <FileName>" exit 5 fi if [ ! -f "$VIDEODIR/$FILENAME" ]; then echo "File does not exist: $VIDEODIR/$FILENAME" exit 6 fi #create temp file name FILENAMEPREFIX="${CHAN}_${START}" INFILEPATH="$VIDEODIR/$FILENAME" TEMPFILEPATH="$INFILEPATH.tmp" #log any output, be sure the user running this script can write to /tmp LOGFOLDERPATH="/tmp/mythtv/commercialRemoval" if [ ! -d "$LOGFOLDERPATH" ]; then mkdir -p $LOGFOLDERPATH fi LOG="$LOGFOLDERPATH/${FILENAMEPREFIX}.log" echo "Generating cutlist..." mythutil -q --gencutlist --chanid $CHAN --starttime $START > /dev/null 2>&1 ERROR=$? if [ $ERROR -ne 0 ]; then echo "Generating cutlist failed for ${FILENAME} with error $ERROR" >> $LOG 2>&1 exit $ERROR fi echo "Transcoding..." mythtranscode --honorcutlist --allkeys -v all,jobqueue --showprogress --mpeg2 -i $INFILEPATH -o $TEMPFILEPATH > /dev/null 2>&1 ERROR=$? if [ $ERROR -ne 0 ]; then echo "Transcoding failed for ${FILENAME} with error $ERROR" >> $LOG 2>&1 exit $ERROR fi #Overwrite the original file with the transcoded file mv -f $TEMPFILEPATH $INFILEPATH #clear out the old cutlist echo "Clearing cutlist..." mythutil -q --clearcutlist --chanid $CHAN --starttime $START > /dev/null 2>&1 echo "Clearing skiplist..." mythutil -q --clearskiplist --chanid $CHAN --starttime $START > /dev/null 2>&1 #Determine new filesize to update the db with UPDATEDFILESIZE=$(du -b $INFILEPATH | awk '{print $1}') #Get mythtv database information from /etc/mythtv/mysql.txt file DBSERVER=$( grep "DBHostName=" /etc/mythtv/mysql.txt | sed s/.*DBHostName=/\/ ) DBUSER=$( grep "DBUserName=" /etc/mythtv/mysql.txt | sed s/.*DBUserName=/\/ ) DBNAME=$( grep "DBName=" /etc/mythtv/mysql.txt | sed s/.*DBName=/\/ ) # Determine database password DBPASS=$( grep "DBPassword=" /etc/mythtv/mysql.txt | sed s/.*DBPassword=/\/ ) # Update the database entry for the file size echo "UPDATE recorded SET filesize='${UPDATEDFILESIZE}' WHERE chanid='${CHAN}' && starttime='${START}'" | mysql -h ${DBSERVER} -u ${DBUSER} --password=${DBPASS} ${DBNAME} echo "Commericals removed for $FILENAME" exit 0
Version: 0.27
|
Works with 0.27 |
- MythGrid