Talk:Script - RemoveCommercials
From MythTV
I'm getting an error on mythtranscode that says Invalid video codec. The -m switch appears to fix the problem. -- jpn627
- This appears to be due to NULL values in the videocodec / audiocodec columns in the recordingprofiles table. A bypass for this problem is to use mythfrontend to update the recording profiles (under TV Settings) and edit each profile under the Transcoders group.--Jbrusey 11:55, 22 October 2006 (UTC)
Is there a way to allow this script to transcode from RTJpeg to MPEG4 while cutting out commercials? Nuvexport can do this but I don't think it updates the database. I have my transcoding defaults set to transcode to mpeg4, and this script will throw an error if the input video is RTJpeg. The error is "Transcoding aborted, NuppelVideoPlayer is not in raw audio mode." I've also tried recording in both raw audio and mp3. I'll post more info on my profile page. Napsilan 17:25, 27 June 2007 (UTC)
Contents |
honorcutlist and mpeg2 lossless transcoding
Update:
Mythtranscode cannot load the cutlist from the filename alone when using the mpeg2 lossless transcoding. Another way to do this is to call mythtranscode with the chanid and starttime parameters. So the user job is modified as such.
removecommercials %DIR% %FILE% %CHANID% %STARTTIME%
Then the script can be modified as such.
CHANID=$3
STARTTIME=`echo $4 | sed -e 's/\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3-\4-\5/'`
....
mythtranscode --mpgeg2 --honorcutlist -c $CHANID -s $STARTTIME -o $VIDEODIR/$FILENAME.tmp
Original:
I had to modify the mythtranscode line to place --honorcutlist after the -i {file} option when doing mpeg2-to-mpeg2 lossless transcoding. I do not know if this change is necessary for any other transcode type, but it should be safe to make the change for any type.
Here is a link to that part of the source. It will not fully process this option unless found_infile, which is set true when processing option i.
P.S. It turns out that alone was not the problem. For some reason the cutlist is not loading upon transcode. So, I added:
CUTLIST=$(mythcommflag --getcutlist -f $VIDEODIR/$FILENAME | tail -n 1 | awk '{print $2}' | sed 's/,/ /g')
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Copying cutlist failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi
Then I supply that to mythtranscode:
mythtranscode --mpeg2 -i $VIDEODIR/$FILENAME --honorcutlist "$CUTLIST" -o $VIDEODIR/$FILENAME.tmp
Already Flagged Recordings
What possibilities exist for modifying the script to detect whether a recording has already been commflaged? For example, I set all my recordings to be automatically commflaged but I only want to remove commercials for certain recordings. Whether I decide to remove the commercials won't be decided at scheduling time, so disabling the commflag job and keeping only the removecommercial job won't do. As it stands, removecommercials reruns the commflag job. I see no switch on mythcommflag that would allow an ifcheck on whether a recording is already flagged.
One idea: mythcommflag --getskiplist -f filename.mpg
I'm waiting for an unflagged program to show up on my system to test what the result of that command on an unflagged program returns.
Here is a way you might be able to check for commercial flagging:
% mysql -u mythtv -pmythtv -B -N -e "select commflagged from recorded where basename = '${FILENAME}'" mythconverg
It will return 1 if the program is already flagged.
Automatically delete old file
It would be nice, and I suspect fairly easy, to have the removecommercials script optionally delete the backup '.old' file. Perhaps a script option such as: removecommercials --deleteoriginal %DIR% %FILE%
Alatar 06:55, 30 May 2007 (UTC)
enhanced script uses channelID and starttime throughout
Create two user jobs, if you like. add SKIP as the last parameter for the second user job. I call it "Remove Commercials, transcode only". Useful if you already have a cutlist. Seems to work better when mythtranscode and mythcommflag are given program parms instead of the file. I have only used it with --mpeg2 so YMMV. -Rick
WARNING BELOW
- Shouldn't it be " if ! [ -f blah ] " INSTEAD OF " if [ ! -f blah ] " in the shell script below?
#!/bin/sh
### removecommercials - for mythtv user job.
### $author Zack White - zwhite dash mythtv a t nospam darkstar deleteme frop dot org
### $Modified 20080330 Richard Hendershot - rshendershot a t nospam gmail deleteme dot youknowcom
# initialize; all except SKIP are required for this to function correctly
declare VIDEODIR=$1
declare FILENAME=$2
declare CHANID=$3
declare STARTTIME=`echo $4 | sed -e 's/\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1-\2-\3-\4-\5-\6/'`
declare SKIP=$5
# for lossless transcoding autodetect. Set to empty string for rtJpeg/mpeg4.
declare MPEG2=--mpeg2
if [ -z "${VIDEODIR}" -o -z "${FILENAME}" -o -z "${CHANID}" -o -z "${STARTTIME}" ]; then
echo "Usage: $0 <VideoDirectory> <FileName> <ChannelID> <StartTime> [SKIP]"
exit 5
fi
if [ ! -f "${VIDEODIR}/${FILENAME}" ]; then
echo "File does not exist: ${VIDEODIR}/${FILENAME}"
exit 6
fi
if [ ! -d "${VIDEODIR}" ]; then
echo "<VideoDirectory> must be a directory"
exit 7
fi
if [ ! -d "${VIDEODIR}/originals" ]; then
cd "${VIDEODIR}"
mkdir originals
fi
if [ ! -d "${VIDEODIR}/originals" ]; then
echo "you must have write access to <VideoDirectory>"
exit 8
fi
if [ -z "${SKIP}" ]; then
# if transcode was run after mythcommflag in the normal setup screens
# then the current file may not match the existing index, so rebuild
echo "mythcommflag: Rebuilding seek list"
mythcommflag -c ${CHANID} -s ${STARTTIME} --quiet --rebuild
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "mythcommflag: Rebuilding seek list failed for ${FILENAME} with error $ERROR"
exit $ERROR
else
echo "mythcommflag: Rebuilding seek list successful for ${FILENAME}"
fi
# flag commercials (generate skiplist)
# you can use mythcommflag -f ${VIDEODIR}/${FILENAME} --getskiplist
# to view results
echo "mythcommflag: Commercial flagging"
mythcommflag -c ${CHANID} -s ${STARTTIME} --quiet
ERROR=$?
if [ $ERROR -gt 126 ]; then
echo "mythcommflag: Commercial flagging failed for ${FILENAME} with error $ERROR"
exit $ERROR
else
echo "mythcommflag: Commercial flagging successful for ${FILENAME}"
fi
# generate cutlist from skiplist
# you can use mythcommflag -f ${VIDEODIR}/${FILENAME} --getcutlist
# to view results
echo "mythcommflag: Creating cutlist from skiplist"
mythcommflag -c ${CHANID} -s ${STARTTIME} --quiet --gencutlist
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "mythcommflag: Creating cutlist from skiplist failed for ${FILENAME} with error $ERROR"
exit $ERROR
else
echo "mythcommflag: Creating cutlist from skiplist successful for ${FILENAME}"
fi
else
echo "mythcommflag: skipping commercial detection due to parameter $SKIP"
fi #end skip
# cut the cruft from the file. creates a new file and a map file.
echo "mythtranscode: Transcoding cruft out of original file (${FILENAME})"
mythtranscode -c ${CHANID} -s ${STARTTIME} $MPEG2 --honorcutlist -o "${VIDEODIR}/${FILENAME}.mpeg"
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "mythtranscode: Transcoding failed for ${FILENAME} with error $ERROR"
exit $ERROR
else
echo "mythtranscode: Transcoding successful for ${FILENAME}"
fi
echo "Moving ${VIDEODIR}/${FILENAME} to ${VIDEODIR}/originals/${FILENAME}"
mv "${VIDEODIR}/${FILENAME}" "${VIDEODIR}/originals"
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "file: Moving failed with error $ERROR"
exit $ERROR
else
echo "file: Moving successful"
fi
echo "Moving ${VIDEODIR}/${FILENAME}.mpeg to ${VIDEODIR}/${FILENAME}"
if [ ! -f "${VIDEODIR}/${FILENAME}" ]; then
mv "${VIDEODIR}/${FILENAME}.mpeg" "${VIDEODIR}/${FILENAME}"
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "file: Moving failed with error $ERROR"
exit $ERROR
else
echo "file: Moving successful"
fi
else
echo "file: cannot replace original. skipping file move. (${VIDEODIR}/${FILENAME})"
fi
echo "file: removing map file: ${VIDEODIR}/${FILENAME}.mpeg.map"
if [ -f "${VIDEODIR}/${FILENAME}.mpeg.map" ]; then
rm "${VIDEODIR}/${FILENAME}.mpeg.map"
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "file: unable to remove map file: ${VIDEODIR}/${FILENAME}.mpeg.map"
else
echo "file: removed map file successfully"
fi
fi
# file has changed, rebuild index
mythcommflag -c ${CHANID} -s ${STARTTIME} --quiet --rebuild
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "mythcommflag: Rebuilding seek list failed for ${FILENAME} with error $ERROR"
exit $ERROR
else
echo "mythcommflag: Rebuilding seek list successful for ${FILENAME}"
fi
mythcommflag -c ${CHANID} -s ${STARTTIME} --quiet --clearcutlist
ERROR=$?
if [ $ERROR -eq 0 ]; then
echo "mythcommflag: Clearing cutlist successful for ${FILENAME}"
# 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 "mythcommflag: Clearing cutlist failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi
