[FFmpeg-user] How to detect commercials in recorded TV stream?

Leo Butler leo.butler81 at googlemail.com
Sat Mar 27 18:48:03 EET 2021


Rob Hallam <ffmpeg at roberthallam.com> writes:

> On Sat, 27 Mar 2021 at 11:39, Peter White <peter.white at posteo.net> wrote:
>>
>> On Sat, Mar 27, 2021 at 08:15:23AM +0100, Bo Berglund wrote:
>> > I am using ffmpeg in scripts to download from a live stream TV channel nightly
>> > so I can view the shows in the morning.
>>
>> I also seem to remember that there are some filters that can detect the
>> start of commercials, by leveraging the logo of the station which
>> usually is not shown during those breaks. But I have no idea if such
>> filters exist for ffmpeg.
>
> Another observation which used to hold true- commercials used to be louder
> on average than the main programme, at least in the anglosphere. Perhaps the
> list of keyframe candidates to skip between could be narrowed down based on
> audio, or a sudden change in audio level.
>
> If you know the rough time interval on which commercials occur, eg
> around 15 / 20
> minutes, that could also filter out keyframe candidates.
>
> However, as Peter says, it would be worth tracking down other projects that
> do advert break detection before coming up with your own heuristics as the
> work may already have been done for you!

Mythtv has decent commercial detection. I am pretty sure that you can
even set it up to record those streamed videos, and then run commercial
detection immediately afterward. The frontend has a built-in editor that
lets you review and revise the cut points. There are loads of scripts
out there that use ffmpeg to then remove the cuts.

Having said that, ffmpeg has the blackdetect, blackframe and
silencedetect filters, which may serve your narrowly-stated purpose. In
the US, they likely won't, but elsewhere they may work better.

Leo


More information about the ffmpeg-user mailing list