FORUMS: list search recent posts

detecting black frames in a video file

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Grzegorz Kwiatkowski
detecting black frames in a video file
on Jan 25, 2014 at 5:32:16 am

My production house is looking for a solution that is able to detect black frames in a video file (mov, mp4, avi). The black level treshold should be customizable. The result could be outputed to a txt file eith timecodes or absolute frames.

I could pay something for a ready solution.


Return to posts index

Michael Rampe
Re: detecting black frames in a video file
on Jan 25, 2014 at 6:32:38 am

http://www.ffmpeg.org/ffmpeg-filters.html#blackdetect

Free of charge.

;-)

Michael


Return to posts index

Grzegorz Kwiatkowski
Re: detecting black frames in a video file
on Jan 25, 2014 at 7:15:23 am

Thanks Michael,

I am a total noob when comes to ffmpeg. Do I have to know something before I download the filter? How to apply it?

M


Return to posts index


Michael Rampe
Re: detecting black frames in a video file
on Jan 25, 2014 at 7:36:41 am

The filters are all installed by default... no need to download them.

basic syntax (on a unix like system) is:
ffmpeg -i inputfile.mp4 -vf blackdetect=d=0.1:pix_th=.1 -f rawvideo -y /dev/null

d=0.1 expresses the minimum length of black to detect in seconds. Lower this if you want single frames.
pix_th=.1 is the level of black to detect between 0 and 1. a setting of one will flag all frames, a setting of .01 should only grab black. tweak as needed.

What system are you working on? (Mac, Windows or Linux?)
Do you have a recent FFmpeg installed already?

Michael


Return to posts index

Grzegorz Kwiatkowski
Re: detecting black frames in a video file
on Jan 25, 2014 at 10:56:14 am

Michael,

I am working on Windows machine. I want to analyze mostly mov (DNxHD codec) and MP4 (AVC codec) files. I don't have FFmpeg installed. I am a proffessional editor but total FFmpeg noob - never used it. Can you explain me step by step what do do?

Thanks man


Return to posts index

Michael Rampe
Re: detecting black frames in a video file
on Jan 25, 2014 at 11:29:14 am

Download a static build for windows from http://www.ffmpeg.org (hit the downloads tab)

There are heaps of "getting started with ffmpeg on windows" guides on the web. Do some googling as I am not a big windows user.... I mostly work on unix systems (osx or Linux flavors).

One thing I do know, you will want to replace the /dev/null in my example with NUL in windows Cmd. (That bit of the command just pipes the output to nowhere so you don't have to deal with temp files) Apart from that, the previously posted command should work just fine and give you a list of black frames detected.

Good luck,

Michael


Return to posts index


Grzegorz Kwiatkowski
Re: detecting black frames in a video file
on Jan 25, 2014 at 12:24:22 pm

Michael,

cooool! It works man :-)

Can it give results in absolute frames or in video timecode (SMPTE EBU)?



M


Return to posts index

Michael Rampe
Re: detecting black frames in a video file
on Jan 25, 2014 at 12:39:32 pm

Nice.

I don't think blackdetect does frames although there is a similar filter called blackframe which does according to the docs.

http://www.ffmpeg.org/ffmpeg-filters.html#blackframe

Just replace -vf blackdetect.... With -vf blackframe

Keep in mind that frame numbers in ffmpeg start at 0 not 1 so you might need to offset the result by 1 if you are using it in some editing packages.

Michael


Return to posts index

Grzegorz Kwiatkowski
Re: detecting black frames in a video file
on Jan 26, 2014 at 11:20:09 am

Michael,

two more questions:

1. blackframe outputs absolute frames and this is better but it also outputs every single black frame instead of ranges (like blackdetect does). Can I customize this filter somehow? If not I'll stick with blackdetect

2. I am also looking for a tool to detect very short scenes (1 frame to 1 second long). Can FFmpeg detect scene changes?


thanks very much


Return to posts index


Michael Rampe
Re: detecting black frames in a video file
on Jan 26, 2014 at 11:49:46 pm

1. Looks like it is one or the other according to the docs.

2. Scene detection can be a bit tricky but I did get a method working a while ago after some searching....
ffprobe -show_frames -f lavfi "movie=Input.mp4,select=gt(scene\,.1)" | grep "pkt_pts_time="
| sed 's/.*pkt_pts_time=([0-9.]{8,})\|.*/\1/'

This gives me a list of times, like this:

214.347467
649.982667
657.289967
664.897567
664.964300
694.960933
722.088033
732.598533
733.432700
733.933200
739.472067
740.339600
754.954200
769.935833
799.899100
829.962467
1192.191000
1193.358833


Basically using the "select" filter with the FFprobe app: http://www.ffmpeg.org/ffmpeg-filters.html#select_002c-aselect
...with some unix fanciness to get a clean text output. The grep/sed pipes wont work under windows...

FFprobe is a separate binary to FFmpeg but you should be able to get a static build from the same place you got the other one.

Michael


Return to posts index

Grzegorz Kwiatkowski
Re: detecting black frames in a video file
on Feb 9, 2014 at 5:53:23 am

Michael,

I am a Windows user. Will the script work without grep/sed pipes?


Return to posts index

Grzegorz Kwiatkowski
Re: detecting black frames in a video file
on Feb 9, 2014 at 2:17:15 pm

I just found a script regarding scene detection:

ffprobe -show_frames -of compact=p=0 -f lavfi "movie=MOVIEFILENAME,select=gt(scene\,.4)" > MOVIEFILENAME.csv

It works fine but is there any parameter that will make it detect only SHORT scenes?


Return to posts index


batzin gerz
Re: detecting black frames in a video file
on Feb 26, 2017 at 8:49:58 pm

Hello!

I have read your answer to that question.. very interesting..

I'm looking for a way of AUTO TRIM the final part of video recordings made from old VHS.. i record a lot of time because i cant stop the recording (during the night).. so my video file reach a point where there is JUST noise (when nothing recorded) or blue screen (when tape reachs end).. so it will be nice cutting the final part in a AUTO way (now i use Movavi Video Split manually)..

Do you think there is any way of doing that? In blue screen the bitrate comes down.. i record in 7500kbps and i think it will be great cutting all "low bitrate part" at the end of the movie.. Something like.. (find the first 5 seconds segment of blue screen (less than 1000kbp) and remove video from that point)..

Thanks in advance.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]