PDA

View Full Version : For loop in a filter


kingmob
10th September 2004, 16:16
Is it possible to put a for loop in a function/filter? I tried out something like follows, but i'm afraid this is for coding dlls, which i have no clue how that works.

Function AverageLines(clip c)
{
c = SelectEvery(c,25,0)
clip d = c.Trim(0,-1)
int F = c.Framecount
float w = 1/F
for (i=1; i < F; i++)
{
c = Trim(0,i)
MergeChroma(d, c, w)
MergeLuma(d, c, w)
}
return C
}

So how should I do this, or is there simply no way?

Manao
10th September 2004, 16:27
You can make recursive functions : just give as a parameter the loop counter. For example : Function LoopCrop(clip c, int margin)
{
return ( margin <= 0 ) ? c : LoopCrop(c.crop(4,4,-4,-4), margin - 4)
}

kingmob
10th September 2004, 19:32
That's a really cumbersome way to create a loop. Trying to create my loop now, but it's giving me a headache :|.
Is there no other, more logical, way?

stickboy
10th September 2004, 19:52
You could try my WhileEval function from my ApplyEvery plug-in (http://www.avisynth.org/stickboy/). It's slow and not very efficient, but still should be faster and more stack-friendly than the recursive case.

But I'll be surprised if it works for what you want, since in your case you'd be generating over N * 3 clips for an input clip of N frames. It wouldn't take much to exhaust AviSynth's limited stack.

kingmob
10th September 2004, 20:16
What i want is to average several frames from the clip to one frame, thus bringing out some static anomalies. But if i try to use the recursive case, avisynth starts moaning about wrong input for the filters, while it's fine :|. Well apparantly not, but it's not as simple as a typo.

For instance, now i have this (because yv12lutxy didn't work):

Function AverageLines(clip c)
{
global c = SelectEvery(c,25,0)
F = (c.Framecount)
d = c.Trim(0,-1).yv12lut(yexpr="x F /",uexpr="x F /",vexpr="x F /")
i = 1
Loopje(d,i,F)
return d
}
#
#======================================================================================================
#
Function Loopje(clip d, int i, int F)
{
return ( i > F ) ? d : Loopje(c.Trim(i,-1).MergeChroma(d,last,(1/F)).MergeLuma(d,last,(1/F)),\
i + 1, F)
}

Avisynth claims the input is wrong in MergeChroma, but i wouldn't know what?

stickboy
11th September 2004, 04:22
The input is wrong to MergeChroma.

You're calling it as:
clip1.MergeChroma(clip2, clip3, weight)It should be either:
MergeChroma(clip1, clip2, weight)orclip1.MergeChroma(clip2, weight)

kingmob
11th September 2004, 12:50
Hmm, thought i already tried that. But it seems it works now, so i owe you a thank you.