Log in

View Full Version : Creating a wrapper and understanding avisynth api:


OvejaNegra
8th July 2012, 05:22
Hi, little help requested:
Yatta has an AVS wrapper that load scripts, apply some filters (tivtc for example), get a requested frame for presenting it on a control


and then is able to change parameters to the filter (tivtc) in realtime and refresh the frame without reloading the entire

script.

I'm trying to do something similar:

Load a script, apply some filters (like tivtc, levels, tweak, one at time), get the frame, present it on a control and then,
change parameters of the filter (like tweak or TFM ) refreshing the frame so i can see the changes.

For that goal, im thinking on creating a wrapper in c++ that i can use on .net languages (because i have 3 programs on VB.net).
The wrapper could export a pointer
to the final frame and from there, i expect convert it to dib (if is not a dib) for using it on a picture box or some other control.


I'm trying to make a working code on c++ to understand the api better (on this case, im using image writer to write the frame
to the disc). This code is working right now:

nt _tmain(int argc, _TCHAR* argv[])
{




try


IScriptEnvironment* env = CreateScriptEnvironment();

AVSValue up_args1[1] = {"C:/01.jpg"};
AVSValue input = env->Invoke("ImageReader", AVSValue(up_args1,1));


AVSValue up_args2[1] = {input};
AVSValue yv12 = env->Invoke("ConvertToYV12", AVSValue(up_args2,1));


AVSValue up_args6[2] = {yv12,"TEST"};
AVSValue inf = env->Invoke("Subtitle", AVSValue(up_args6,2));


AVSValue up_args5[1] = {inf};
AVSValue rgb = env->Invoke("ConvertToRGB", AVSValue(up_args5,1));



AVSValue up_args4[5] = {rgb, "C:/",0,0,"jpg"};
PClip clip = env->Invoke("ImageWriter", AVSValue(up_args4,5)).AsClip();


clip->GetFrame(0,env);


catch (AvisynthError err)

{
_tprintf(_T("%s\n"), err.msg);}



return 0;
}


Questions:
How can i change a parameter of a filter (subtitle test to test2 for example ) and call clip->GetFrame again without destroying
and realoading all again?

PVideoFrame FrameX = Clip->GetFrame( 0, env); is enough to get a pointer to a complete frame on memory?

what the use of FrameX->GetWritePtr();?
Whats inside of FrameX? An array of int with x,y and rgb values for the three chanels? (and if the picture is YV12?)

Of course, the idea of making the wrapper and export the pointer to FrameX seems the more quick way to me, but any other
idea is well received.

Sorry for the bad english, thanks.

Myrsloik
8th July 2012, 15:04
The secret in Yatta is that I actually rebuild the filter chain from after the source filter. A lot. So no real secret there. Creating (and destroying) most filters is actually a very fast operation, the only big exceptions being source filters (avisource, dgdecode and so on).
Simply keep the clip you get from the source filter and reuse it when you rebuild the filters chain after it.

OvejaNegra
9th July 2012, 17:32
sorry i dont see how.
A roug code if possible thanks.
No wait:
Delete clip,
change all the values except AVSValue input = env->Invoke("ImageReader", AVSValue(up_args1,1));,
and then
PClip clip = env->Invoke("ImageWriter", AVSValue(up_args4,5)).AsClip();


clip->GetFrame(0,env);

again? (roghly of course)
Something like that?
Because if i open YMC and change teh values of TFM the change it's allmost instantaneous, i want to replicate that.
Thanks