View Full Version : Auto drop dark frames
luders
10th September 2008, 07:08
I am working on a time laps video created from 100's of thousands of pictures. I have made shorter videos already using something like the following but with the huge size of the new one I need a way to cut out dark frames (images early in the morning or late at night) so that the footage looks clean and not flashy. Is there a way to do this automatically in avisynth like drop a certain luminescence level? Deleting the actual files that are dark would take weeks just to pull a view of the images up and sort on the computer. Any help would be extremely helpful.
ImageSource("C:\2008-0313-0314\%05d.jpg", start=00001, end=19043, fps=2500
Crop(150,490,-1450,-390)
ChangeFPS(240)
ConvertFPS(160)
ConvertFPS(110)
ConvertFPS(90)
ConvertFPS(60)
ConvertFPS(40)
ConvertFPS(29.97)
vampiredom
10th September 2008, 08:19
I don't know exactly how you can do the frame removal, but there may be something better (and faster) you can try for the framerate conversion: Consider using BlendFPS() -- from motion.dll -- instead of you multiple ConvertFPS statements:
AssumeFPS(2500)
BlendFPS(29.97, aperture = 8.0)
J_Darnley
10th September 2008, 11:29
It sounds like you want ConditionalFilter and the AverageLuma runtime function.
ConditionalFilter(last, last, trim(last,1,0), "AverageLuma()", "greaterthan", "20")
[EDIT] But this won't work completely for sequences of more than 1 dark frame.
[EDIT2] This might work better.
ScriptClip( "( AverageLuma() > 20 ) ? last : DeleteFrame(last, current_frame)" )
Gavino
10th September 2008, 16:14
This might work better.
ScriptClip( "( AverageLuma() > 20 ) ? last : DeleteFrame(last, current_frame)" )
I don't think that will work either, because the DeleteFrame is not done cumulatively (if that's the right word). In effect it will be the same as your ConditionalFilter suggestion.
luders
10th September 2008, 21:49
Thanks for the suggestions that certainly helps. If it is thought that those suggestions wont work for multiple dark frames in a row, are there any other suggestions?
Gavino
11th September 2008, 00:38
The problem with the earlier ideas was not just with consecutive dark frames. Since each dark frame was simply replaced by the immediately following frame, they would also have repeated good frames following dark ones.
It's a tricky one. To make the deletions cumulative, the run-time script has to use a variable to remember what it has already done, and to detect a run of dark frames, a recursive function is needed.
function DarkFrames(clip c, int current_frame, int thresh) {
# returns the number of consecutive 'dark' frames at the current frame
AverageLuma(c) > thresh ? 0
\ : (current_frame >= c.frameCount-1) ? 1
\ : 1 + DarkFrames(c.Trim(1,0), current_frame, thresh)
}
threshold = 20 # <- change this to suit requirements
offset = 0
# assume 'last' set earlier in script
ScriptClip("""
offset = offset + DarkFrames(Trim(offset, 0), current_frame, threshold)
Trim(offset, 0)
""")
For this to work properly, the script must be rendered strictly linearly from start to finish.
Note that the last 'good' frame is repeated up to the end of the clip as ScriptClip cannot change the overall length.
vampiredom
11th September 2008, 01:31
Excellent, Gavino. Your script is a great example of how these kinds of things can be done. You could also use something very much like this for arbitrary (unsynced) duplicate frame removal.
If Luders can deal with the manual trimming of the repeat end frames he should be in good shape. I also stand by my earlier suggestion of using BlendFPS -- excellent for timelapse stuff.
Luders -- are really really trying to remove ALL dark frames, or rather just dark frames with bright neighbors? If the latter is the case you may want to try something like:
(AverageLuma(c) > Thresh || YDifferenceToNext(c) < DiffThresh) ? 0 : ...etc.
luders
11th September 2008, 02:32
Yeah I do want to remove all dark frames. This might be a little out of my league but I will sure as heck give it a try right now.
Gavino
11th September 2008, 10:51
Previously, I said:Note that the last 'good' frame is repeated up to the end of the clip ...
In fact, it is simply the last frame (good or bad) of the original which is repeated at the end of the output clip (the number of repetitions being equal to the number of dark frames deleted).
You could perhaps make manual detection of the 'real' end easier by appending a blank frame to the original before processing. That way you end up with a sequence of blank frames at the end of the output.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.