[FFmpeg-user] How to use ffmpeg to detect commercials

Bo Berglund bo.berglund at gmail.com
Thu Sep 30 15:35:27 EEST 2021

On Wed, 29 Sep 2021 09:45:43 +0200, Bo Berglund <bo.berglund at gmail.com> wrote:

>I am recording news streams off of the Internet using an automated system during
>my nights so I can view them at daytime in my time zone. This works OK but...
>Is there a way to have ffmpeg detect where in the video commercials start and
>One item that is different between the program and the commercial is that in the
>program there is a logo at a fixed position on screen (MSNBC, CNN or the like).
>Can ffmpeg be set up to detect the start and end of scenes containing this logo
>and produce a clip text file with the start and duration of these video
>Or better yet make an output video only containing the scenes with the logo?
>Or is there a different working way to do this?

I searched similar questions and found this regarding blackdetect filter on

It uses ffprobe and I tested it on one of my 64 minute videos and it could
detect a number of black sections with start/end pairs:

ffprobe -f lavfi -i "movie=myvideo.mp4,blackdetect[out0]" -show_entries
tags=lavfi.black_start,lavfi.black_end -of default=nw=1 -v quiet

But in this case there were a number of false detections as well (black sections
within a commercial block) and each output was duplicated tike this:


So it is hard to use as base for cutting out the commercials.

What I would like is a detection like this but instead of blackness using a
defined image and possibly position on the screen as the item to find.
If I could get a list of times where the image is present (start/end pairs) it
would be the wanted solution.

If the "filter" could be done to output start-end time pairs I could use this to
automate commercial removal....

Bo Berglund
Developer in Sweden

More information about the ffmpeg-user mailing list