PDA

View Full Version : using invoke to make a new frame


Wilbert
30th October 2003, 22:38
I want to invoke ConvertToRGB to make a new frame:


#include "windows.h"
#include "avisynth.h"

class color : public GenericVideoFilter {
PClip clip;

public:
color(PClip _child, IScriptEnvironment* env);
~color();
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
};

color::color(PClip _child, IScriptEnvironment* env) :
GenericVideoFilter(_child) {
AVSValue args[1] = { child };
clip = env->Invoke("ConvertToRGB",AVSValue(args,1)).AsClip();
}

color::~color() {
}

PVideoFrame __stdcall color::GetFrame(int n, IScriptEnvironment* env) {

//PVideoFrame src = child->GetFrame(n, env);
//PVideoFrame dst = env->NewVideoFrame(vi);
PVideoFrame test = clip->GetFrame(n, env);

return test;
}

AVSValue __cdecl Create_color(AVSValue args, void* user_data, IScriptEnvironment* env) {
return new color(args[0].AsClip(), env);
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
{
env->AddFunction("color", "c", Create_color, 0);
return 0;
}


Of course this is not correct. WMP gives an access violation (feeding avs with an YUY2 clip). What am I doing wrong?

Kurosu
31st October 2003, 01:35
Check avisynth source and convert.cpp: you'll notice that, as for many filters, if you modify the properties of a video between input and output, you must modify the vi object.

In that case (untested), you need to put in the constructor:


vi.pixel_type = VideoInfo::CS_BGR32;

I guess the crash wasn't occuring inside avisynth.

Btw, the code tag is [ code][ /code]. Too much HTML/XML recently ? :D

Wilbert
1st November 2003, 17:05
Thanks, that worked.

Btw, the code tag is [ code][ /code]. Too much HTML/XML recently ? :)
Yeah. This, html and wiki. If I do some of them at the same time, I never get it right at first.