Log in

View Full Version : script-variables in plugins


hanfrunz
24th April 2006, 16:16
I have a problem understanding how avisynth manages script-variables.

example1: avs-script
text="test123"
colorbars(300,200)
subtitle(text)
okay this gives me colorbars with "test123" on it

example2: avs-script
colorbars(300,200)
testfilter() # this sets text to "test345"
subtitle(text)
example2: cpp-file (constructor)
env->SetVar("text","test345")

okay this gives me colorbars with "test345" on it.

If i put the SetVar()-stuff in the GetFrame-method nothing happens. So i assume it is not possible to set script-vars in the GetFrame-method. Only in the constructor of a filter.
Can one of the core-developers tell me if this is right or do i miss something? Will this the possible in avs3?

This is done in the dvinfo() filter but does it work (can't test it right now)?

thanks,
hanfrunz

tsp
24th April 2006, 18:20
you can use SetVar in GetFrame but the variables are resolved during construction of the filterchain so "text" in this case is resolved before testfilter->GetFrame() is called. Try calling ScriptEvaluate("subtitle(text") after a testfilter that change the content in the GetFrame and you will see it is posible to use SetVar in GetFrame (I use it in some of my filters to output how long it takes to calculate a frame).

hanfrunz
25th April 2006, 11:50
hello tsp,

is ScriptEvaluate() a script-function or do i use it in my c++ code?

thanks,
hanfrunz

sh0dan
25th April 2006, 15:18
I think tsp meant ScriptClip. To modify your example 2:

global text="" #Set default.
colorbars(300,200)
testfilter() # this sets text to "test345"
ScriptClip("subtitle(text)", after_frame=true)

hanfrunz
25th April 2006, 16:19
Hello shOdan,
yes it's scriptclip, i also found that. This works pretty good, a little bit complicated... but it works.

So i can work on the GetPixelColor() funtion again :)

hanfrunz

WarpEnterprises
27th April 2006, 15:46
...in DVInfo I do basically the same:

env->SetVar("rec_time",rec_time);
...
args[1] = env->Invoke("Eval",AVSValue(args,1));

so Invoke is the "C-equivalent" of ScriptClip

hanfrunz
27th April 2006, 18:31
mmh i think they use the ->Invoke("Eval") to evaluate the output string.
They use another ->Invoke("Subtitle... to print the values on the screen. But you also have to use ScriptClip to acces al the variables set in the GetFrame-method. Would it be possible to change this behavior of avisynth. So that filters can return values? Maybe in Version 3?

hanfrunz

EDIT:

i found another problem. My filter sets the value of an integer lets say x=55. If I use Scriptclip("subtitle(String(x))") i get an errormessage: i don't know what x means. If i set x in the script before (x=1) then the output is "55".
Is there a way to use the string() command inside of the Subtitle() command without declaring all variables?

tsp
27th April 2006, 19:04
remember to use after_frame=true in scriptclip else the value from the previous frame is used(this produces the error you get in the first frame because there are no previous frame)

hanfrunz
27th April 2006, 19:28
thanks tsp,
but that doesn't change the behavior. The problem is that the String()-function does not know x because it's in the same "world" as the rest of the script. Only Subtitle() knows about x because ScriptClip() told it that x is 55. This is all very weird :)

IanB
28th April 2006, 04:21
... Would it be possible to change this behavior of avisynth. So that filters can return values? ...Filters already return an AVSValue, 99% of which are a PClip but there is nothing stopping you coding for an Int, Float, String, Bool, or Array. In the 1% that do it already are the conditional functions. Think of the occasional times you have had the error "Script does not return a Clip".

The tricky bit will be making use of this. GetFrame and GetAudio are integrally related to a PClip.

stickboy
28th April 2006, 05:04
I have a problem understanding how avisynth manages script-variables.Exactly what are you doing anyway where you need to access ScriptClip variables from another filter?

hanfrunz
28th April 2006, 08:23
It's all about the PGET() function i'm coding right now. PGET() gets the rgb/yuv values of a pixel and sets three variables (r,g,b or y,u,v). Other filters can use these values to do whatever you like. In the PixelInfo-thread we discussed if it is possible to return these values. So i tried to understand how avisynth manges variables...

tsp
28th April 2006, 09:47
I never had any probem like yours using string inside ScriptClip with variables set in GetFrame. Very strange.
In medianblur I set the variable Debug in GetFrame that contains the time in milisec that it takes to process the frame inside medianblur and this script works just fine:

blackness().converttoyv12()
medianblur()
scriptclip("subtitle(string(Debug))",after_frame=true)