Log in

View Full Version : Best method for For Next Loop?


ScottZ
29th September 2005, 08:40
I've been experimenting with a few filters by manually plugging in parameters and then looking at results in VirtualDub.

In simple terms, is it possible to:

text overlay the parameter value
play the clip through
increment the parameter of the filter
text overlay the parameter value
play the clip through again
repeat at the increment until a maximum value for the parameter has been met


Best way I could describe it is as a For.. Next loop

After looking through AVISynth commands and some batch options, I haven't been able to come up with a very good solution.

Thanks

stickboy
29th September 2005, 08:47
Use recursion.
function Foo(clip c, int n)
{
Assert(n >= 0)
return (n == 1)
\ ? c
\ : c ++ Foo(c, n - 1)
}

trolltuning
29th September 2005, 15:51
@Scottz
When you get this working could you post the full script please?

gzarkadas
29th September 2005, 16:20
If the number of values you want to simultaneously test are no more than about 80, then you can install the AVSLib (http://sourceforge.net/projects/avslib/) library and use the array support that provides to create your desired result (for installing and using it see its documentation (http://avslib.sourceforge.net/)).

The procedure is simple:

A. Wrap your filter processing to a function taking two arguments (more can be added, but then I would had to explain more; see the library's documentation if you want more arguments).

# val is used so that either ints or floats can be used
Function myfilter(val param, clip c) {
# do here all filter processing wanted on clip c
# end with a line like this to text overlay the parameter value
return c.SubTitle(String(param))
}

B. Then assign to this variable your clip; note that the "global" is necessary.
global testclip = ...

C. The rest of the script is the following three lines. What they do is straightforward

create an array of values (replace start, step, end with the actual values you want),
apply your filter(s) wrapper function to testclip and store the results into an array,
sum all array elements (with simple UnallignedSplice) to get a signle clip.

pmvalues = ArrayRange (http://avslib.sourceforge.net/functions/a.html#ArrayRange)(start, end, step)
pmclips = pmvalues.ArrayOpFunc (http://avslib.sourceforge.net/functions/a.html#ArrayOpFunc)("myfilter", "testclip")
return pmclips.ArraySum (http://avslib.sourceforge.net/functions/a.html#ArraySum)()
That's it; enjoy!

wuziq
12th March 2007, 19:58
Use recursion.
function Foo(clip c, int n)
{
Assert(n >= 0)
return (n == 1)
\ ? c
\ : c ++ Foo(c, n - 1)
}


sorry to dig up an old thread, but why is the Assert needed?

gzarkadas
12th March 2007, 22:38
sorry to dig up an old thread, but why is the Assert needed?

To avoid infinite recursion if one carelessly use a n less than zero (Assert == algorithm's conditions OK check) .

stickboy
13th March 2007, 10:14
sorry to dig up an old thread, but why is the Assert needed?To make sure input is in the expected form.

But what was I thinking? Did I really write that? It should have been Assert(n > 0). Argh.

(In this case, it doesn't really matter since calling it with n=0 would cause the failure to happen on the next iteration instead. I'm still very ashamed though.)