Auto Detect Ad Breaks

Status
Not open for further replies.

njm

Member
Is there a hook available to allow you to run code once any recording (encrypted or decrypted) has finished? Preferably after decryption for encrypted recordings.
 
Yes. There's recmon that runs a script/program on completion of any recording (e.g. recmon /bin/echo).
Or the automatic background processing has a postdecrypt hook that is used by things like badnts and arbookmarks - see /mod/webif/plugin/badnts/auto.hook for a relatively simple example if you have badnts installed.
 
Loooking at webif/lib/bin/auto, it looks like postdecrypt only runs if a file was actually decrypted, so it doesn't run for SD recordings. Is that right?
 
Ah, my code wasn't running because I was using unencrypt rather than auto-decrypt. Woops!
 
Would you care to share what you are using it for? You never know when something might be of interest to someone else...

Edit: This thread wasn't called "Auto Detect Ad Breaks" when I wrote this.
 
I'm using it to flag ad breaks with bookmarks using this algorithm here: http://www.mythtv.org/wiki/Commercial_detection_with_silence_for_UK_freeviewHD

It's simple enough to run on the Humax because it only processes the audio (there are short silences between ads, which the linked program groups together into clusters and marks as ads breaks). It works quite well. I've tried it with Fargo and Derek. Managed to skip all the ads in this weeks episode of Fargo just by pressing the bookmark button at the start of each ad break. Just got it set up to run on the decryption hook. Looks promising.

Right now I'm using the silence.cpp program from that link compiled on the Humax, parsing the output in jim, and setting bookmarks using the hmt command. Using this silence program isn't ideal because it requires libsndfile, which also has to be compiled on the Humax. I think it would be better to use ffmpeg to detect the silences and then implement the clustering with jim, that way there are less dependencies to install.

Once I've done some more testing of course I'll share my findings/code.
 
Wow. Combine this with the new bookmark GUI and the crop function, and it will add a significant level of functionality to the CF - it's a game changer. Previous discussion of this topic has considered it not feasible on the HDR-FOX.

Do you think the topic should be renamed something like "Auto-Detect Ad Breaks", maybe?

I don't think you need to worry about the "hooks" - once you have a process which can be run on a decrypted recording that brackets ad breaks with bookmarks, af123 will integrate it into the WebIF auto system.

Does it also detect the preamble and postamble on non-commercial services?
 
Very nice indeed!

Using this silence program isn't ideal because it requires libsndfile, which also has to be compiled on the Humax. I think it would be better to use ffmpeg to detect the silences and then implement the clustering with jim, that way there are less dependencies to install.
Adding a libsndfile package to the repository (and a dependency for whatever package you come up with) isn't a problem so don't let that stop you. ffmpeg has become quite a large beast so may be overkill for this but implementing the cluster detection in Jim would be an interesting project too : )

I don't think you need to worry about the "hooks" - once you have a process which can be run on a decrypted recording that brackets ad breaks with bookmarks, af123 will integrate it into the WebIF auto system.

That postdecrypt hook is exactly how to integrate it into the auto system - it's how the arbookmarks package - which does a similar thing to this in terms of analysing the file and placing a bookmark - works. I think the hook framework might need to support priorities soon though so that things are run in a predictable order.
 
ffmpeg has become quite a large beast so may be overkill for this but implementing the cluster detection in Jim would be an interesting project too : )
The input to the silence program is decoded audio from ffmpeg. Using the ffmpeg silencedetect filter rather than a separate silence detect program would reduce the number of places this could go wrong (and potentially speed it up?). I couldn't get the silencedetect filter to work with the version of ffmpeg on the Fox-HDR - has it been compiled with all the necessary options? It didn't recognise the -af (audio filter) argument.

It takes ~15 mins to process a ~30 min recording. I scheduled some recordings overnight and today, so hopefully I'll get some more timings when I get home.

Do you think the topic should be renamed something like "Auto-Detect Ad Breaks", maybe?
That's fine by me.
 
. I couldn't get the silencedetect filter to work with the version of ffmpeg on the Fox-HDR - has it been compiled with all the necessary options? It didn't recognise the -af (audio filter) argument.

It wasn't deliberately excluded. I'll check this evening.
 
The version of ffmpeg in the repository is pretty old. I've built and uploaded the latest version which supports audio filters if you want to give it a go. I haven't put it into the main repository yet as I need to test it first but you can install it from the command line with:

Code:
humax# opkg install http://hpkg.tv/hdrfoxt2/test/ffmpeg_2.2.3_mipsel.opk
 
Coo! Count me in! The days of pressing Next Chapter 4 times to skip adverts may soon be over.

I can't see it working, though. Silences in programmes and non-silent sponsored lead-ins to programmes may fool it.
 
(ffmpeg) I've built and uploaded the latest version which supports audio filters if you want to give it a go.

Actually, 2.2.3 doesn't seem to work properly. Try 2.1.4 instead:

Code:
humax# opkg install http://hpkg.tv/hdrfoxt2/test/ffmpeg_2.1.4_mipsel.opk
 
I can't see it working, though. Silences in programmes and non-silent sponsored lead-ins to programmes may fool it.
Maybe, but the bookmark editor will allow for manual correction. Any initial setting of bookmarks will be a help.
 
njm has sent me the files for packaging up as a beta! I've added a fairly rough web interface and uploaded it to the test repository. @njm, I've made a couple of minor tweaks too that I'll send you separately.

You can now install the beta package by running the detectads diagnostic!

The package installs a new option on the OPT+ dropdown against a recording that takes you to the web interface. The recording needs to be decrypted first so that the audio stream can be analysed. Running the analysis will produce output at the bottom of the screen and, when it's finished, add bookmarks bracketing the detected ads. In the testing I've done, it's very accurate even just using the same general parameters for all channels. (The final version would probably allow for a database of different settings for each channel or provider.)

Have a play if you're interested and let us know how you get on.
 
Tested on a half-hour ITV programme, and confirm it works! Now running on a 2h10m film (StDef).

The bookmarks get added to any existing bookmarks - eg output from arbookmarks, which confuses the issue a bit and will make the crop selection out of sync. I wonder whether the detectads bookmarking should replace all existing bookmarks instead of adding to them?

Update: processing the film took 37 minutes.
 
Status
Not open for further replies.
Back
Top