Log in

View Full Version : Fastest way to open avs Scripts in C++ ?


ruanova
26th May 2005, 10:30
Hi,
What's the fastest way to open .avs Scripts in C++ / C# ?

Using Avisynth.dll directly via Invoke("Import"... ?
Via AVIFile...?

Please, can help me..?
And can show me any source code ...?


(I need open .avs script and show frames in a window form....)

Thank in advance...

Guest
26th May 2005, 13:45
Five minutes with the Forum Search function yielded this ("opening AVS" in Development and Avisynth Development):

http://forum.doom9.org/showthread.php?s=&threadid=45830

http://forum.doom9.org/showthread.php?s=&threadid=32007

http://forum.doom9.org/showthread.php?s=&threadid=21412

The simplest approach is just to use the standard VFW AVI interface: AVIFileOpen()/AVIFileGetStream()/AVIStreamRead() etc.

ruanova
27th May 2005, 08:58
Thanks neuron2 ...

This thread http://forum.doom9.org/showthread.php?s=&threadid=32007
is the way that I used :

{

typedef IScriptEnvironment * __stdcall FUNC(int);

HINSTANCE lib = LoadLibrary("avisynth.dll");
FUNC *func = (FUNC *)GetProcAddress(lib, "CreateScriptEnvironment");
IScriptEnvironment *env = func(AVISYNTH_INTERFACE_VERSION);

try {


AVSValue args[] = { "a.avs" };


AVSValue theScript = env->Invoke("Import", AVSValue( &AVSValue(args,1),1));

PClip theVideo = theScript.AsClip();

const VideoInfo& theVideoInfo = theVideo->GetVideoInfo();

printf("%d %d %d", theVideoInfo.width, theVideoInfo.height, theVideoInfo.BitsPerPixel());
}
catch(IScriptEnvironment::NotFound) {
env->ThrowError("No es posible");
}

delete env;
FreeLibrary(lib);

}




This little code, in Microsoft Visual C++ 6.0, runs ok ... but I use Borland C++ Builder 6, and the code compile ok, but the line env->Invoke("Import" ...) halt and Exception on AviSynth.dll.

Have you any idea...?


Thank
(Sorry, I'm not English speaker)

sh0dan
27th May 2005, 21:36
MSVC is the only way to go, since the binary structure of classes is different from compiler to compiler. You could have a look at the avisynth_c interface. It's a bit more tedious, and not very well tested. Use search.

ruanova
30th May 2005, 07:34
Thanks again ...

but, why this code runs ok?:

typedef IScriptEnvironment * __stdcall FUNC(int);

HINSTANCE lib = LoadLibrary("avisynth.dll");
FUNC *func = (FUNC *)GetProcAddress(lib, "CreateScriptEnvironment");
IScriptEnvironment *env = func(AVISYNTH_INTERFACE_VERSION);

try {
AVSValue x;

if( env->FunctionExists("Import" ))
{
ShowMessage("Yes, the IMPORT function exist.");
} else {
ShowMessage("NO, the IMPORT function don't exist.");
}

if(env->SetVar("$PluginDir$", AVSValue( "c:\\" )))
{
ShowMessage("SetVar ok.");
} else {
ShowMessage("SetVar fails.");
}


But now, in env->GetVar(...) and env->Invode(...), fails...


try {
const char* plugin_dir;
plugin_dir = env->GetVar("$PluginDir$").AsString();
ShowMessage( plugin_dir );
} catch(...) {
ShowMessage("Plugin directory not set.");
}


AVSValue theScript;

try {
theScript = env->Invoke("Import", AVSValue( &AVSValue(args,0),1));
} catch(...) {
ShowMessage("Invoke 1 FAILS.");
env->ThrowError("MyFilterError: Whoa! Could not Invoke reduce!");
}


Perharps the error are in AVSValue param...?