Activity › Forums › Compression Techniques › detecting black frames in a video file
-
detecting black frames in a video file
Posted by Grzegorz Kwiatkowski on January 25, 2014 at 5:32 amMy 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.
Batzin Gerz replied 9 years, 2 months ago 3 Members · 12 Replies -
12 Replies
-
Michael Rampe
January 25, 2014 at 6:32 am -
Grzegorz Kwiatkowski
January 25, 2014 at 7:15 amThanks 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
-
Michael Rampe
January 25, 2014 at 7:36 amThe 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/nulld=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
-
Grzegorz Kwiatkowski
January 25, 2014 at 10:56 amMichael,
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
-
Michael Rampe
January 25, 2014 at 11:29 amDownload a static build for windows from https://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
-
Grzegorz Kwiatkowski
January 25, 2014 at 12:24 pmMichael,
cooool! It works man 🙂
Can it give results in absolute frames or in video timecode (SMPTE EBU)?
M
-
Michael Rampe
January 25, 2014 at 12:39 pmNice.
I don’t think blackdetect does frames although there is a similar filter called blackframe which does according to the docs.
https://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
-
Grzegorz Kwiatkowski
January 26, 2014 at 11:20 amMichael,
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
-
Michael Rampe
January 26, 2014 at 11:49 pm1. 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.358833Basically using the “select” filter with the FFprobe app: https://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
-
Grzegorz Kwiatkowski
February 9, 2014 at 5:53 amMichael,
I am a Windows user. Will the script work without grep/sed pipes?
Reply to this Discussion! Login or Sign Up