Log in

View Full Version : Can't get ConditionalFilter woking inside a Function


mustardman
20th November 2004, 05:13
My script works fine as a start-to-end script, but it looked bad and was quite repeditive and long. So I decided to put the repeated bits into a function. But...I can't seem to get the ConditionalFilter to operate inside the function, yet it works fine outside!

The basis of my script is

Function SelectBest(clip IN, int X)
{
Selector = crop(IN,0,0,720,2).ConvertToYV12
Modified = Overlay(IN,In with some changes)
Best = ConditionalFilter(IN,IN,Modified, "AverageLuma(Selector)",">","50",true)
Return(Best)
}

But it keeps returning the error, "I dont know what Selector means" or somthing very similar.

I tried moving the lines around, after searching for help, I read that the function works from the bottom up. But this made it worse, it shifted the error to occur even sooner in ConditionalFilter.

My exact script is...

# Function examines top line to find jitter caused by bad Vsync. This leaves a black
# line, which can be detected with luma. Problem is, the jitter is random.

Function ShiftUp2 (clip FullFrame,int Threshold)
{
Trim = Crop(FullFrame,0,0,720,2).ConvertToYV12
ShiftFrame = Overlay(FullFrame,FullFrame,x=0,y=-2,mode="blend") # Image shifted up by 2 lines
Shifted = ConditionalFilter(FullFrame,FullFrame,ShiftFrame,"AverageLuma(Trim)",">","Threshold",true)
Return(Shifted)
}

c = AVISource("e:\recovery\rgb\s01-shoot.avi").AssumeFrameBased.AssumeBFF.SeparateFields

FF = BiLinearResize(c,720,576)

#lots of stuff deleted which does the bit inside the function several times linearly...

Return(ShiftUp2(FF,50))

Thanks,
MM

stickboy
20th November 2004, 07:36
I think you need to declare "Selector" as being global.

I believe this is explained (with examples) in the ConditionalFilter documentation.

mustardman
23rd November 2004, 09:37
Yes, that was the problem - thanks stickboy. I remember reading that stuff quite some time ago, but couldn't find it without doing some more serious surfing. Perhaps a link could be inserted into the help doco?

Another problem, now that I have the function working properly, I can't call it recursively... it causes VDub to simply exit with no warning or delay. It just vanishes! Take the P2 line out, and it works just fine.

My script... the details of the operation are probably not that important (and probably a bit hard to grasp what I am trying to do...)


# Does the function " IF (L1 > (L2 * 1.2)) THEN null ELSE shift "

Function ShiftUp2(clip Frame)
{
global Line1 = Crop(Frame,0,0,720,2).ConvertToYV12
global Line2 = Crop(Frame,0,2,720,2).ConvertToYV12

Shift = Overlay(Frame,Frame,x=0,y=-2,mode="blend") # Image shifted up by 2 lines
Result= ConditionalFilter(Frame,Frame,Shift,"AverageLuma(Line1)",">","AverageLuma(Line2)*1.2")
Return(Result)
}


c = AVISource("f:\recovery\rgb\c01.avi").AssumeFrameBased.AssumeBFF.SeparateFields

FF = BiLinearResize(c,720,576).AssumeFPS(25)


P1 = ShiftUp2(FF)
P2 = ShiftUp2(P1)

Return(P2)

I don't know if you would really say it was recursive, it dosen't call itself from within itself, but the last few lines could be written "return(shiftup2(shiftup2(FF)))", so it is really called in a recursive fashion.

stickboy
23rd November 2004, 10:44
Originally posted by mustardman
Yes, that was the problem - thanks stickboy. I remember reading that stuff quite some time ago, but couldn't find it without doing some more serious surfing. Perhaps a link could be inserted into the help doco?Huh? It's in the documentation included with AviSynth:
Advanced conditional filtering: part I

...

An other important issue is that only global defined variables in the conditional filter 'environment' can be used outside (and vice versa). Have a look at the following script ...(Docs/english/corefilters/conditionalfilter.htm)

Didée
23rd November 2004, 11:46
Originally posted by mustardman
Another problem, now that I have the function working properly, I can't call it recursively... it causes VDub to simply exit with no warning or delay. It just vanishes! Take the P2 line out, and it works just fine.
That's normal. The farthest I ever got when recursively calling anything related to the conditional environment, was an "access violation" instead of a vanishing application ;)

mustardman
24th November 2004, 11:47
@stickboy : sorry. I was looking directly under the 'filter reference (filtersbycategory)' available directly through the "manual". I did not delve deeper into the separate pieces of documentation (until later) - I suppose I sort of expected a link straight from the brief description. That is what I meant by a link in the doco, I should have been more specific.

@didee : Thanks. Good to know it is not just me then! Looks like I'll have to go back to lots of repeditive lines of script, rather than (as I had hoped) a nice script with a few functions and calling them appropriately!

MM

stickboy
24th November 2004, 12:54
Originally posted by mustardman
I suppose I sort of expected a link straight from the brief description. That is what I meant by a link in the doco, I should have been more specific.There is a link. Click on the filter name. (And this is true for the both the online documentation at avisynth.org and the documentation that comes with AviSynth. It doesn't matter in this case, since the documentation for ConditionalFilter appears to be the same in both places... but you generally should be specific about which one you're referring to.)