[FFmpeg-user] How to use ffmpeg to detect commercials
Bo Berglund
bo.berglund at gmail.com
Fri Oct 1 11:11:28 EEST 2021
On Thu, 30 Sep 2021 14:35:27 +0200, Bo Berglund <bo.berglund at gmail.com> wrote:
>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
I have realized from comments here that the logo detection scheme is not really
workable, so I am back to using this blackdetect method.
One thing tah bugs me is that the command shown above duplicates the output
value on two lines, how can I make ffprobe output only one line for each
detection?
It would be easier to process in a script if the output was like this instead:
TAG:lavfi.black_start=55.533
TAG:lavfi.black_end=57.833
TAG:lavfi.black_start=778.467
TAG:lavfi.black_end=779.067
TAG:lavfi.black_start=839.033
TAG:lavfi.black_end=839.067
Then a start is followed by an end and so on and the time between the start and
end shows if a commercial insertion is found (short time between start and end)
or if there is a deliberate long black section (which I would anyway want to
exclude).
So:
- How can i modify the ffprobe command such that it outputs just one line for
every start or end point? I am not clever enough to figure out how ffprobe
actually works...
- I notice a detection that lasts only 34 ms, could such be valid at all? It
seems like a single video frame...
--
Bo Berglund
Developer in Sweden
More information about the ffmpeg-user
mailing list