View Full Version : Filter SDK: How to create new PClip of PVideoFrames?
I want to invoke a internal filter (resizer) and feed it with two temporary images I created.
Since I cannot invoke a filter with PVideoFrame, I need to create a new PClip with my two PVideoFrames, how can I do that?
I looking for something like this:
PClip tmpin, tmpout;
PVideoFrame inA, inB, outA, outB;
tmpin = env->NewClip(vi);
...
tmpin->AddFrame(inA);
tmpin->AddFrame(inB);
AVSValue args[...] = { tmpin, ... };
tmpout = env->Invoke("Resize",AVSValue(args,...)).AsClip();
outA = tmpout->GetFrame(0,env);
outB = tmpout->GetFrame(1,env);
Is something like this possible or is there another solution?
Gavino
30th June 2011, 14:04
Define a new subclass of IClip whose GetFrame() returns inA for frame 0 and inB for frame 1, then create an instance of it. inA and inB could be made parameters of the constructor. You will also have to provide appropriate implementations of the other virtual functions of IClip in your new class - see GenericVideoFilter in avisynth.h for a guide.
IanB
30th June 2011, 14:06
You want to create a source filter. Have a look at how BlankClip works (avisynth\src\sources\source.cpp) (http://avisynth2.cvs.sourceforge.net/viewvc/avisynth2/avisynth/src/sources/source.cpp?revision=1.30&view=markup). Its a bit messy with all the argument parsing code, just ignore that part.
class StaticImage : public IClip {
const VideoInfo vi;
const PVideoFrame frame;
bool parity;
public:
StaticImage(const VideoInfo& _vi, const PVideoFrame& _frame, bool _parity)
: vi(_vi), frame(_frame), parity(_parity) {}
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) { return frame; }
void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) {
memset(buf, 0, (size_t)vi.BytesFromAudioSamples(count));
}
const VideoInfo& __stdcall GetVideoInfo() { return vi; }
bool __stdcall GetParity(int n) { return (vi.IsFieldBased() ? (n&1) : false) ^ parity; }
int __stdcall SetCacheHints(int cachehints,int frame_range) { return 0; };
};Doctor the GetFrame implementation to return the pixel data you require.
Fill out a VideoInfo structure to represent your clip.static AVSValue __cdecl Create_BlankClip(AVSValue args, void*, IScriptEnvironment* env) {
VideoInfo vi_default;
memset(&vi_default, 0, sizeof(VideoInfo));
VideoInfo vi = vi_default;
vi_default.fps_denominator=1;
vi_default.fps_numerator=24;
vi_default.height=480;
vi_default.pixel_type=VideoInfo::CS_BGR32;
vi_default.num_frames=240;
vi_default.width=640;
vi_default.audio_samples_per_second=44100;
vi_default.nchannels=1;
vi_default.num_audio_samples=44100*10;
vi_default.sample_type=SAMPLE_INT16;
vi_default.SetFieldBased(false);
....
Thanks, I´ve used the subclass method, that was mostly copy&paste from avisynth.h.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.