Kodi Community Forum

Full Version: How To: Convert mythcommflag markers to chapter marks within a transcoded file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I liked the fact that Kodi can handle an EDL for commercial markers provided by MythTV or even an external text source file for its markers. What I didn't like is that it ignores the EDL once I've transcoded my recordings to an mp4 file with HandBrake. Apparently the framerate does not get calculated correctly while playing one of my mp4 files (shows 0 framerate in the info screen during playback) and because it is 0, the EDL code section is skipped. Seems to match up with this thread: 237747 (thread)
I am not running .28 nor am I ready to do so since I am running MythTV on FreeBSD and don't feel like compiling my own (.27.5 is available in freshports). Oddly I do transcode with constant framerate using --cfr option in my HandBrake command line.

Since I need to transcode my recordings to conserve space, I came up with an alternate way to handle commercials. Basically in my user job to transcode my recording, right after I do the transcoding process, I call mythcommflag on the new .mp4 to work its magic and mark the commercials. I then select out the ending commercial flags (type 5 in the recordedmarkup table) and build a temporary chapter file (I called chapfile) that is compatible with mp4box utility ( https://gpac.wp.mines-telecom.fr/mp4box/ ) that can merge in the chapter flags with the video & audio streams to create a new mp4 container file. I then move this new file back into my recordings directory and update the database with the new file size, filename and transcoded flag set. I also delete out the recordedmarkup table entries since the chapter markers are now permanent within the mp4 container. Here's the section showing the chapter creation with an explanation of the variables used (this is bourne shell, btw):
$DBUSER = your mysql user name
$DBPASSWD = your mysql user password
$CHAN = channel ID as a passed in argument
$START = start time of recording as a passed in argument
$OUTFILE = basename of new mp4 file (basically basename from recorded table with updated mp4 extension instead of mpg)
$VIDEODIR = directory to your recordings
$CHAPCNT = just an incremental chapter count to be used in the chapter name

Code:
# Mark commercials and set chapter markers in actual MP4 container file
# mythcommflag returns number of commercials as its exit code. Only numbers 128+ are an error code.
mythcommflag --file $OUTFILE --quiet
ERROR=$?
if [ $ERROR -gt 127 ]; then
   echo "Error creating commercial markers for $OUTFILE  with error $ERROR" >> errors.log
   exit $ERROR
fi
MARKLIST=`mysql -B --skip-column-names -u$DBUSER -p$DBPASSWD mythconverg -e "select mark from recordedmarkup where chanid='$CHAN' and starttime='$START' and type='5' order by mark;"`
for FRAME in $MARKLIST
do
  echo "AddChapter($FRAME,Commercial $CHAPCNT)" >> chapfile
  CHAPCNT=`expr $CHAPCNT + 1`
done
mp4box -noprog -quiet -add $OUTFILE -chap chapfile $VIDEODIR/$OUTFILE
ERROR=$?
if [ $ERROR -ne 0 ]; then
  echo "Error in mp4box adding chapters. Check chapfile for accuracy. Error code: $ERROR" >> errors.log
  exit $ERROR
fi

# Clean up recordedmarkup table since we do not need the markers after chapter creation
mysql -u$DBUSER -p$DBPASSWD mythconverg -e "delete from recordedmarkup where chanid='$CHAN' and starttime='$START';"

If you would like to see the entire script for what I do to transcode, I can paste that too if it would help to see. I figured I'd share this to start with for those wanting an alternate way to skip commercials without cutting them completely in case of detection errors. That was my main hang up; I didn't want to lose part of the show and wanted the option to rewind if necessary to go back through a commercial to get the part of the show if incorrectly marked.
(2016-08-15, 21:16)zakaron Wrote: [ -> ]If you would like to see the entire script for what I do to transcode, I can paste that too if it would help to see. I figured I'd share this to start with for those wanting an alternate way to skip commercials without cutting them completely in case of detection errors. That was my main hang up; I didn't want to lose part of the show and wanted the option to rewind if necessary to go back through a commercial to get the part of the show if incorrectly marked.

I would love to see your whole setup. I have the exact same issue. Too many times I have been burned by comm skipping cutting out part of the actual show. I like the fact that kodi can use a skip list so you don't actually have to physically chop them out and lose it for ever.

So yeah, I would be very interesting in your process.