Silence-detect.sh
This is a proof of concept script that looks for blocks of silence to locate commercial breaks in the UK.
It works surprisingly well; but on some channels puts the break the wrong side of the "sponsor". Seems to work on (at least) Film 4, ITV1-4 and Dave.
The script relies on ffmpeg to extract the audio and then uses mp3splt to locate the silence.
Run the script as silence-detect.sh filename. Note that it will not insert a cutlist if there is already one present, and it does not delete the largish (200MB or so) temporary files afterwards.
#!/bin/bash MP3SPLT_OPTS="th=-70,min=0.15" [[ "Cutlist: " == `mythcommflag --getcutlist -f $1 |grep Cutlist` ]] \ || { echo already has cutlist && exit 1; } TMPDIR=`mktemp -d /tmp/mythcommflag.XXXXXX` || exit 1 cd $TMPDIR touch `basename $1`.touch ffmpeg -i $1 -acodec copy sound.mp3 mp3splt -s -p $MP3SPLT_OPTS sound.mp3 CUTLIST=`tail --lines=+3 mp3splt.log|sort -g |\ awk 'BEGIN{start=0;ORS=","}{if($2-start<400) {finish=$2} else {print int(start*25+1)"-"int(finish*25-25); start=$1; finish=$2;}}END{print int(start*25+1)"-"}'` mythcommflag --setcutlist $CUTLIST -f $1
This is obviously a complete hack! The logic in the middle lines is that advert break often have other bits of silence in them so we coalesce up to 400 seconds into one break.
A user has developed this script into a wrapper for mythcommflag called mythcommflag-wrapper that is targeted at usage with UK TV.