Log in

View Full Version : Fishy conditional behaviour


mf
30th September 2003, 21:51
I'm having some weird problem along with Molloy. He asked me about a script, and we've been testing some stuff, and I came to the conclusion somewhere, something is wrong (no ****, sherlock :D).

Now let's first make this clear:
1) YDifferenceFromPrevious() has a clip as its first parameter, right?
2) YDifferenceFromPrevious() returns a numeric value, right?
3) If I do condition1 = (numeric_var > numeric_value), then condition1 is a boolean, and without any syntax errors, right?

Now if 1), 2) and 3) are correct, this should work:
AVISource("file.avi")
blargh = last

condition1 = (YDifferenceFromPrevious(blargh) > 42.0)
condition2 = (UDifferenceFromPrevious(blargh) > 60.0)

ScriptClip(blargh, "(condition1 && condition2) ? Blackness(blargh) : blargh")

But, it doesn't. (Invalid Arguments to function YDifferenceFromPrevious)
This does work:
AVISource("file.avi")
blargh = last

condition1 = IsClip(blargh)
condition2 = IsBool(condition1)

ScriptClip(blargh, "(condition1 && condition2) ? Blackness(blargh) : blargh")

Proving me that at least my last line is correct. And making me doubt about points 1), 2) and 3). So, am I doing something wrong or is there some weird bug in AVISynth?

sh0dan
1st October 2003, 15:40
YDifferenceFromPrevious() can ONLY be used within conditional functions, as it changes on every frame. Also remember that conditional variables must be assigned bottom up.

Using something like your syntax:

global condition1 = false
global condition2 = false
blargh = last
black = blankclip(last)

ScriptClip("(condition1 && condition2) ? black : last")

frameevaluate("condition1 =(YDifferenceFromPrevious(blargh) > 2.0)")
frameevaluate("condition2 = (UDifferenceFromPrevious(blargh) > 1.0)")


Simpler (and faster) syntax:


untouched = last
blargh = blankclip(last)

conditionalfilter(untouched, blargh, untouched, "(YDifferenceFromPrevious(last) > 2.0) && (UDifferenceFromPrevious(last) > 1.0)", "=", "true", true)


or even:


global condition1 = false
global condition2 = false

untouched = last
blargh = blankclip(last)

conditionalfilter(last, blargh, last, "(condition1 && condition2)", "=", "true", true)

frameevaluate(last, "condition1 =(YDifferenceFromPrevious(untouched) > 2.0)")
frameevaluate(last, "condition2 = (UDifferenceFromPrevious(untouched) > 1.0)")

Pick your poison.

Didée
2nd October 2003, 02:09
Originally posted by sh0dan
YDifferenceFromPrevious() can ONLY be used within conditional functions That was already clear. Then I thought I were clever and tried sth like

function Myfunction(clip c) {
global xyz = AverageLuma(c)
return( c )
}
#---------------------
scriptclip( last, "Myfunction(source)" )

since 'AverageLuma' is only called from within a conditional function - but this doesn't work either.

BTW, if no-one ever tried: I found it is no good idea trying to build a rekursive function structure when the structure contains any conditional filters ... ;) - Application vanishes.

- Didée

mf
2nd October 2003, 13:52
Thanks. It'd be nicer if it'd just work with existing functions instead of being a kind of hack like that, but I guess it IS difficult to integrate it smoothly. Anyway, as this was my very first time dealing with conditional filtering (as I said, it was Molloy who probed my interest in this, because he wanted to know how to do something), I didn't know about conditional stuff only being able to be used inside conditional functions. Still, interesting stuff.