[MPlayer-dev-eng] Black frame detection

Julian Hall jules at meridiandigital.co.uk
Thu Jul 6 09:48:57 CEST 2006


I've been looking for a while for a command-line program that would 
produce a list of black or nearly-black frames in a video source.  The 
closest I could find was in 'avidemux', but that requires the GUI to do 
it, so wasn't really convenient for me.

Yesterday, I finally decided to get off my backside and code one up.  
I've written it as a filter for mplayer, and have attached the source 
file in case anybody else would find it useful.  Primary application I 
had in mind (i.e., what I wanted to use it for) was to produce chapter 
lists for DVD production from downloaded AVIs that have fade-to-black 
sequences at appropriate points.

The filter is based on code I found here:
   http://lists.mplayerhq.hu/pipermail/mplayer-users/2003-May/032941.html
and simply prints a list of the frame numbers of black frames onto 
stderr.  It does not pass the image to further filters in the chain, as 
I wanted this to be able to run as quickly as possible.  Typical usage 
would be:
   /usr/local/bin/mencoder -ovc lavc -nosound -vf blackframe $input -o 
/dev/null 2>$output
On my 400MHz PII, it can scan a 40 minute XViD video in about 9 minutes, 
which seems like ideal performance to me.

I'm also attaching a python script which may be useful -- it takes the 
output file produced by the above command, looks for groups of black 
frames longer than a certain threshold length and translates the frame 
number of the middle frame of each into a time in a format that can be 
understood by 'dvdauthor'.  Usage is 'getchapters2 [frame-rate 
[threshold]] < $input'.  Default frame rate is 25fps, default threshold 
is 10 frames.  It should be fairly easy to modify (if modifications are 
even necessary) to work with other dvd authoring (or vcd authoring) 
software.

Hope this is useful to someone!

Jules
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: vf_blackframe.c
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20060706/1cfd9ba3/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: getchapters2
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20060706/1cfd9ba3/attachment.asc>


More information about the MPlayer-dev-eng mailing list