Finish the example code on how to write filters
[vapoursynth-svn.git] / sdk / filter_skeleton.c
blob9e768596e35919f46c85ca7ff49d4bb6142fb02c
1 //////////////////////////////////////////
2 // This file contains a simple filter
3 // skeleton you can use to get started.
4 // With no changes it simply passes
5 // frames through.
7 #include "VapourSynth.h"
8 #include "VapourSynth.h"
10 typedef struct {
11 const VSNodeRef *node;
12 VSVideoInfo *vi;
13 } FilterData;
15 static void VS_CC filterInit(VSMap *in, VSMap *out, void **instanceData, VSNode *node, VSCore *core, const VSAPI *vsapi) {
16 FilterData *d = (FilterData *) * instanceData;
17 vsapi->setVideoInfo(d->vi, node);
20 static const VSFrameRef *VS_CC filterGetFrame(int n, int activationReason, void **instanceData, void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi) {
21 FilterData *d = (FilterData *) * instanceData;
23 if (activationReason == arInitial) {
24 vsapi->requestFrameFilter(n, d->node, frameCtx);
25 } else if (activationReason == arAllFramesReady) {
26 const VSFrameRef *frame = vsapi->getFrameFilter(n, d->node, frameCtx);
28 // your code here...
30 return frame;
33 return 0;
36 static void VS_CC filterFree(void *instanceData, VSCore *core, const VSAPI *vsapi) {
37 FilterData *d = (FilterData *)instanceData;
38 vsapi->freeNode(d->node);
39 free(d);
42 static void VS_CC filterCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) {
43 FilterData d;
44 FilterData *data;
45 const VSNodeRef *cref;
47 d.node = vsapi->propGetNode(in, "clip", 0, 0);
48 d.vi = vsapi->getVideoInfo(d.node);
50 data = malloc(sizeof(d));
51 *data = d;
53 cref = vsapi->createFilter(in, out, "Filter", filterInit, filterGetFrame, filterFree, fmParallel, 0, data, core);
54 vsapi->propSetNode(out, "clip", cref, 0);
55 vsapi->freeNode(cref);
56 return;
59 //////////////////////////////////////////
60 // Init
62 void VS_CC filterlibInitialize(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin *plugin) {
63 configFunc("com.example.filter", "filter", "VapourSynth Filter Skeleton", VAPOURSYNTH_API_VERSION, 1, plugin);
64 registerFunc("Filter", "clip:clip;", filterCreate, 0, plugin);