[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
>end?
>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
>sections?
>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
stackoverflow:
https://stackoverflow.com/questions/18722747/can-you-put-the-result-of-a-blackdetect-filter-in-a-textfile-using-ffmpeg/32757533#32757533

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:

TAG:lavfi.black_start=55.533
TAG:lavfi.black_start=55.533
TAG:lavfi.black_end=57.833
TAG:lavfi.black_end=57.833
TAG:lavfi.black_start=778.467
TAG:lavfi.black_start=778.467
TAG:lavfi.black_end=779.067
TAG:lavfi.black_end=779.067
TAG:lavfi.black_start=839.033
TAG:lavfi.black_start=839.033
TAG:lavfi.black_end=839.067
TAG:lavfi.black_end=839.067

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