View Full Version : Filter to average every N frames?
D9JK
30th November 2014, 18:02
Hello,
Is anyone aware of a filter that averages (the entire contents of) every N frames in a clip?
For example:
"AverageFrames(30)" would take the first 30 frames and create a single, averaged frame out of them, and then move on to the next 30 frames. And so on. In this case, the total clip length is of course reduced to 1/30.
To further clarify, "AverageFrames(2)" would be similar to:
A = Clip.SelectEven()
B = Clip.SelectOdd()
Merge(A,B)
But how to do this efficiently for, say, every 30 frames?
Reel.Deel
30th November 2014, 18:22
Have you looked at AvgAll (http://forum.doom9.org/showpost.php?p=1579509) or ClipBlend (http://forum.doom9.org/showthread.php?t=168048)?
StainlessS
30th November 2014, 20:42
Dont think ClipBlend would suit, ClipBlend can output average of previous 30 frames with same o/p as i/p frame count.
If you jump about in the stream [eg SelectEvery(30,29)] then it will 'reset' itself (throw away accumulated ave data)
and start accumulating again, so for every output frame it would reset accumulator and would be no different to a simple SelectEvery(30,29).
You could however do it in two passes
AviSource("d:\1.avi")
ClipBlend(Delay=30-1)
AviSource("d:\2.avi")
SelectEvery(30,29)
Untested but should work I think.
EDIT: "average of previous 30 frames" should read "average of previous 29 + current frames".
StainlessS
30th November 2014, 21:08
This seems to (EDIT: does) work but conversion to RGB, EDIT: but ODD number of averaged frames only
# Temporal Average of 29 frames
avisource("D:\avs\test.avi")
ConvertToRGB24()
RgbAmplifier(Radius=15,Multiplier=0.0) # Radius * 2 - 1 frames averaged (14 before, 14 after + current)
SelectEvery(29,14)
http://forum.doom9.org/showthread.php?t=168293&highlight=RGBAmplifier
D9JK
30th November 2014, 22:08
Sounds good, I'll give it a try. :-)
Thanks to both of you for your help!
colours
3rd December 2014, 17:13
Why not just use TemporalSoften?
It'll have the same limitation of only working when N is odd, but works on YUV too. Or actually, requiring that N is odd isn't too hard to work around…
function blend(clip c,int n)
{
if (n%2 == 0)
{
blended = c.temporalsoften(n/2-1,255,255,255,2).selectevery(n,n/2)
return merge(blended,c.selectevery(n,0),1.0/n)
}
if (n == 1) {return c}
return c.temporalsoften((n-1)/2,255,255,255,2).selectevery(n,(n-1)/2)
}
Needs Avisynth+ for the if statement goodness. (TemporalSoften can also be replaced by RgbAmplifier if you so desire, of course.)
Gavino
3rd December 2014, 17:30
Needs Avisynth+ for the if statement goodness.
Or GScript of course. ;)
creaothceann
3rd December 2014, 21:49
Alternatively:
function blend(clip c, int n) {
(n % 2 == 0) ? Merge( c.TemporalSoften( n / 2 - 1, 255, 255, 255, 2).SelectEvery(n, n / 2), c.SelectEvery(n, 0), 1.0 / n)
\: (n != 1) ? c.TemporalSoften((n - 1) / 2 , 255, 255, 255, 2).SelectEvery(n, (n - 1) / 2)
\: c
}
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.