Log in

View Full Version : Can I/how to use env->Invoke to apply subtitles within filter?


wonkey_monkey
21st August 2012, 20:17
I've written a filter and would like to apply a subtitle from within it - either conditionally per frame or to the whole clip at construction time (as well as doing the filter's usual stuff). I don't really understand env->Invoke(...), but is this something it can be used for?

I've tried adding env->Invoke("invert",""); inside the constructor and GetFrame, but both result in exceptions.

David

Wilbert
21st August 2012, 21:28
See http://avisynth.org/mediawiki/Filter_SDK/Env_Invoke and http://avisynth.org/mediawiki/Cplusplus_API#Invoke for using Invoke.

You can also use ApplyMessage and include "text-overlay.h" (you should license your code GPL in that case though). In v2.60a3 you can also use env->ApplyMessage: http://avisynth.org/mediawiki/Cplusplus_API#ApplyMessage.2C_v5

wonkey_monkey
21st August 2012, 22:36
Thanks Wilbur, that second page nudged me in the right direction.

David

IanB
22nd August 2012, 00:29
The 2nd argument is expected to be an AVSValue of type array, which is a list of the arguments to the function you are invoking.

Typically you might do something like this :-...
AVSValue args[1] = {child};
AVSValue child2 = env->Invoke("invert", AVSValue(args, 1));
...
PVideoFrame src2 = child2->GetFrame(n, env);
...

If the argument list is sparse and you need to provide the names for the arguments, then the optional 3rd argument, a matching array of string pointers, can be provided....
char *text = "Foo has struck!";
...
AVSValue args[4] = {child, text, "Courier", 48};
char* argnames[4] = { 0, 0, "font", "size" };
AVSValue child2 = env->Invoke("Subtitle", AVSValue(args, 4), argnames);
...