PDA

View Full Version : Using avisynth.dll in a command-line program to easily decompress video frames.


Kurosu
3rd November 2003, 23:05
Hi,

I'd like to write a simple command-line proggie (like avs2avi, but with decompressed data to manage). In order to not bother with VfW API, I'd simply like to use Avisynth as much as possible... That would be something like this:

typedef IScriptEnvironment* (__stdcall *MYPROC)(int version = AVISYNTH_INTERFACE_VERSION);

int main(int argc, char* argv[])
{
HINSTANCE hinstLib;
BOOL fRunTimeLinkSuccess = FALSE;
PClip Video;
MYPROC CreateEnv;
IScriptEnvironment *env;

hinstLib = LoadLibrary("avisynth");
if (hinstLib == NULL)
{
fprintf(stderr,"Couldn't load Avisynth.dll\n");
exit(1);
}
CreateEnv = GetProcAddress(hinstLib, "CreateScriptEnvironment");
if (CreateEnv == NULL)
{
fprintf(stderr, "Couldn't access CreateScriptEnvironment\n");
exit(1);
}
env = CreateEnv();
AVSValue args[1] = { "OAV8-1.avi" };
AVSValue &out = env->Invoke("Avisource",AVSValue(args,1));
if (!out.IsClip())
{
fprintf(stderr, "Couldn't create clip object\n");
exit(1);
}
Video = out.AsClip();
//Proceed on with whatever is needed with Video
FreeLibrary(hinstLib);
exit(0);
}

The program crashes on the Invoke call (not the AsClip). Can anybody help on that matter ? (and yes that's a dirty C/C++ mix)

Richard Berg
4th November 2003, 10:04
It probably has something to do with the way the arguments are handled. I could look it up in the code, but I do know that simply using Eval has always worked for me in the past. Example half-stolen from some old code:

string script = "Avisource(\"OAV8-1.avi\")";
PClip clip = avsEnv->Invoke("Eval", script.c_str()).AsClip();

jonny
4th November 2003, 10:25
[Toff] some time ago have posted an example of this on the avs2avi thread (axenc000.zip). Link is down now, you could try to ask him the source, if it still crashes

Bidoche
4th November 2003, 11:28
I think the correct version, should be this :
AVSValue args("OAV8-1.avi");
AVSValue out = env->Invoke("Avisource",AVSValue(args,1));

Kurosu
4th November 2003, 11:44
Originally posted by Bidoche
I think the correct version, should be this :
AVSValue args("OAV8-1.avi");
AVSValue out = env->Invoke("Avisource",AVSValue(args,1));
My bad, the extra '&' was a desesperate (hence _very_ stupid, which I shouldn't have even posted in the first place) attempt. I'll report back on my results (as curiously nobody ever posted about using avisynth.dll for a simple video management).

Unless I left such a "thing" in the code, the error occuring was in the call to Invoke. Btw, how do I use Invoke on a function with only some parameters filled, ie the equivalent of running Avisource("somevideo.avi", pixel_type="YV12") (except by using Eval)?

jonny
4th November 2003, 11:51
(as curiously nobody ever posted about using avisynth.dll to simply video management).
Me :) (i've done experiments some time ago... can't find sources on my hd... perhaps i've trashed all)
http://forum.doom9.org/showthread.php?s=&threadid=51314
(actually i'm using vfw, but the idea of using avisynth.dll it's still quite interesting)

Bidoche
4th November 2003, 12:19
@Kurosu

I am not sure, but Invoke may require all parameters to be filled.
That would explain the crash there then.

Kurosu
4th November 2003, 19:53
Originally posted by jonny Me :) (i've done experiments some time ago... can't find sources on my hd... perhaps i've trashed all)Erm... Sorry
"Use the search button before posting" :(

(actually i'm using vfw, but the idea of using avisynth.dll it's still quite interesting)Well, one less "framework" to learn, and the access is pretty easy... Why reinvent the wheel ?

I'd like to see your code, or [Toff]'s (in which case I'll ask him I guess). And in the hope someone sees an error in my code/project (Multithreaded App), here (http://kurosu.inforezo.org/DropeDupe.zip) is the link to the source code...

So far, both Eval and Invoke with full argumentlist have failed...

Belgabor
4th November 2003, 23:22
Have a look here (http://cvs.sourceforge.net/viewcvs.py/virtualdubmod/VirtualDubMod15/VirtualDub/mod/avs/CAvisynth.cpp?view=markup) (or at the ffdshow sources, which I used for reference), perhaps it helps.

jonny
4th November 2003, 23:42
My vfw code here:
http://jonny.leffe.dnsalias.com/doom9/avs_read.rar
(it compiles on VC6+SP5)

It reads frames from an avs script, usage: "test.exe myscript.avs"
(There is paranoic error checking inside ^^)

Modifying the "Log" function you should be able to use it everywhere (the Log function is to handle error messages, actually it writes in both stdout and in a log file).

Perhaps you could use vfw instead...

Kurosu
5th November 2003, 00:49
Originally posted by jonny My vfw code here
After writing a lengthy reply, I noticed that once again, debugging is a strange art... While the debug decided to stop on a particular point, the program actually ran deeper in the program and was faced with executing a function pointer which was NULL. At least the code cleanly loads the DLL and display the version, so I'll go with that solution (others were: copy Avisynth code or use AVIStreamGetFrame, none of which were appealing).

Thanks all for your help, I'll try to free more time to add my experiment to Avisynth wiki, so as everybody can start writing easily an application. For the record, another question: the app being a standalone and not a dll that needs to export symbols and the like, it seems it could be compiled with any C++ compiler having libs and prototypes for the WIN32 API (for instance gcc), am I wrong?

Richard Berg
5th November 2003, 04:29
As long as you're using a C++ interface (IScriptEnvironment, in this case), the compilers need to generate symbols and vtables and so on identically. So basically, no.