Log in

View Full Version : text color of subtitle while using invoke in avisynth plugin


Ceppo
4th March 2022, 14:44
I need to invoke subtitle into an avisynth plugin and I don't understand how to pass colors using invoke.

int text_color = color_yellow ($FFFF00)
int halo_color = color_black ($000000)

So where can I find the int values of http://avisynth.nl/index.php/Preset_colors ???

wonkey_monkey
4th March 2022, 19:16
Those are the hex values so in C++ you can use them as immediate integers, e.g.

AVSValue args[4] = { clip, "A white centred subtitle", 5, 0x00ffffff };
const char* names[4] = { NULL, NULL, "align", "text_color" };
PClip subtitled_clip = env->Invoke("Subtitle", AVSValue(args, 4), names).AsClip();


If you to want to translate a colour name to an integer you can probably use GetVar:

int yellow = env->GetVar("color_yellow").AsInt();

although there's always a possibility that someone has messed with or lost the .avsi file, in which case this may result in an exception.

Ceppo
4th March 2022, 21:09
Thanks a lot for your help! Very clear explanation :)

StainlessS
4th March 2022, 22:13
in which case this may result in an exception.

A Snippet originally by Gavino,


AVSValue __cdecl GetVar(IScriptEnvironment* env, const char* name) {
try {return env->GetVar(name);} catch (IScriptEnvironment::NotFound) {} return AVSValue();
}


EDIT:
Usage something like [Runtime Filter use; eg AverageLuma {or whatever} on explicit frame n or current_frame, use frame from arg n (if specified), OR, use current_frame ONLY in runtime script {could eg use outside of runtime script, eg for/next loop with supplied FrameNo n}]

int n;
if(args[2].IsInt()) {n = args[2].AsInt(); } // Frame n
else {
AVSValue cn = GetVar(env,"current_frame"); // AVOIDS EXCEPTION, if result is AVSValue as int then succeeded
if (!cn.IsInt()) env->ThrowError("%s'current_frame' only available in runtime scripts",myName);
n = cn.AsInt(); // current_frame
}


EDIT:
// AVOIDS EXCEPTION, if result is AVSValue as int then succeeded
AVSValue as int for specific case of int current_frame,
If Defined as any type then succeeds otherwise undefined failed.

To below,
Kinda missed you
Didn't even know that you were aiming at me.

Ceppo
4th March 2022, 22:30
Thanks, StainlessS. Kinda missed you :)