Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
9th March 2003, 23:59 | #1 | Link |
VDubMod Devel
Join Date: Oct 2001
Location: Germany
Posts: 824
|
Humbly requested: Filter SDK / Easy filter sample
This is kinda a bump on some facts in this old thread. So far I wasn't tempted to program a avisynth filter, but now I am
The problem is I can't find an easy to understand sample source for an AviSynth filter, most sources are just too complicated to understand for a video filter programming newbie like me. What I'm thinking of is a sample working in all colorspaces that manipulates the frame in some simple way (like drawing a centered square on it), perhaps in a future version samples for doing temporal stuff and an source filter. I also would appreciate being pointed to already existing source code fulfilling this conditions (being simple, but for now YUY2 and YV12 would be enough for colorspaces). Thanks in advance Belgabor
__________________
VirtualDubMod [SourceForge : Tracker/DL] (FAQ, Some rules) Be sure to also download the latest DLL package or get the all inclusive package! Before you post questions, please read the VirtualDub and/or VirtualDubMod FAQ. If you have a bug report or feature request for VirtualDubMod, be sure to read the rules first. We give 100% of your donations to the Open Source community |
10th March 2003, 00:33 | #2 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
If you can wait a few days- I'll write one for you.
I guarantee it will be simple regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
10th March 2003, 05:00 | #4 | Link |
developer wannabe
Join Date: Nov 2001
Location: Brooklyn, NY
Posts: 1,211
|
If you want to peek at the implementation of some of the core filters, I'd suggest starting with levels.cpp/h. All the colorspaces are demonstrated* and the algorithms are simple (lookup tables).
*Don't depend on these filters to learn everything, though. There are nuances like RGB being "upside-down" and YV12's alignment issues. @neuron2 - I think the sample you're referring to is actually still on Ben's page. |
10th March 2003, 05:10 | #5 | Link |
Registered User
Join Date: Oct 2001
Location: Gainesville FL USA
Posts: 2,092
|
Belgabor -
Also see the Avisynth 2.5 alpha page. This has a link to the converted Invert filter sample source. - Tom |
10th March 2003, 08:39 | #6 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
I put up some stuff (Ben's and my own) on the FilterSDK page on avisynth.org - you are of course free to ask if you need further information.
__________________
Regards, sh0dan // VoxPod |
10th March 2003, 12:41 | #7 | Link |
VDubMod Devel
Join Date: Oct 2001
Location: Germany
Posts: 824
|
Yay! Thanks so much guys. I will look into it when I get back home this evening
__________________
VirtualDubMod [SourceForge : Tracker/DL] (FAQ, Some rules) Be sure to also download the latest DLL package or get the all inclusive package! Before you post questions, please read the VirtualDub and/or VirtualDubMod FAQ. If you have a bug report or feature request for VirtualDubMod, be sure to read the rules first. We give 100% of your donations to the Open Source community |
10th March 2003, 21:39 | #8 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
SimpleSample 1.0
Here is first one. (available at
http://www.geocities.com/siwalters_u...lesample10.zip (please right-click to download from a geocities site) because I seem to have lost the ability/privliges to attach to either this or the Usuage forum ) All it does is, well, nothing really. It just takes the input and copies it to the output. It doesn't work with YV12 but should work with all other colourspaces (cause its so simple ) The next one will put a square in the middle! regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html Last edited by Si; 7th May 2006 at 08:11. |
11th March 2003, 00:12 | #9 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
Minor plea for change: Move colorspace checks to the constructor:
Code:
class SimpleSample : public GenericVideoFilter { public: SimpleSample(PClip _child) : GenericVideoFilter(_child); } PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); }; SimpleSample(PClip _child) : GenericVideoFilter(_child) { if (vi.IsPlanar()) // is input not planar env->ThrowError("SimpleSample: input to filter must be in YUY2 or RGB"); } RGB formats do actually work with the code you've made! The planar implementation is actually quite easy - you can remove the colorspace check, and do: Code:
[...] const int dst_pitch = dst->GetPitch(); const int dst_width = dst->GetRowSize(); const int dst_height = dst->GetHeight(); const int src_pitch = src->GetPitch(); const int src_width = src->GetRowSize(); const int src_height = src->GetHeight(); int w, h; //Copy src to dst srcp = src->GetReadPtr(); dstp = dst->GetWritePtr(); for (h=0; h < src_height;h++) { for (w = 0; w < src_width; w++) *(dstp + w) = *(srcp + w); srcp = srcp + src_pitch; dstp = dstp + dst_pitch; } // end copy src to dst const int dst_pitchUV = dst->GetPitch(PLANAR_U); const int dst_widthUV = dst->GetRowSize(PLANAR_U); const int dst_heightUV = dst->GetHeight(PLANAR_U); const int src_pitchUV = src->GetPitch(PLANAR_U); const int src_widthUV = src->GetRowSize(PLANAR_U); const int src_heightUV = src->GetHeight(PLANAR_U); //Copy U plane src to dst srcp = src->GetReadPtr(PLANAR_U); dstp = dst->GetWritePtr(PLANAR_U); for (h=0; h < src_heightUV;h++) { for (w = 0; w < src_widthUV; w++) *(dstp + w) = *(srcp + w); srcp = srcp + src_pitchUV; dstp = dstp + dst_pitchUV; } // end copy src to dst //Copy V plane src to dst srcp = src->GetReadPtr(PLANAR_V); dstp = dst->GetWritePtr(PLANAR_V); for (h=0; h < src_heightUV;h++) { for (w = 0; w < src_widthUV; w++) *(dstp + w) = *(srcp + w); srcp = srcp + src_pitchUV; dstp = dstp + dst_pitchUV; } // end copy src to dst [...]
__________________
Regards, sh0dan // VoxPod Last edited by sh0dan; 11th March 2003 at 00:22. |
11th March 2003, 00:43 | #10 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@sh0dan
Whoa Your code Code:
class SimpleSample : public GenericVideoFilter { public: SimpleSample(PClip _child) : GenericVideoFilter(_child); } PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); }; SimpleSample(PClip _child) : GenericVideoFilter(_child) { if (vi.IsPlanar()) // is input not planar env->ThrowError("SimpleSample: input to filter must be in YUY2 or RGB"); } Is it wrong? or is there an problem with my compiler. I normally put the colourspace code "near the beginning" (my speak for somewhere in the constructor bit ) but it wouldn't work with the filter having no parameters . So I temporarily moved it. I know it works with RGB I'll stick your code in for YV12 in the next version.
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
11th March 2003, 08:32 | #11 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
Sorry - a but quick there - env was missing:
Code:
public: SimpleSample(PClip _child, IScriptEnvironment* env); PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); }; SimpleSample::SimpleSample(PClip _child, IScriptEnvironment* env) : GenericVideoFilter(_child) { if (vi.IsPlanar()) // is input not planar env->ThrowError("SimpleSample: input to filter must be in YUY2 or RGB"); } Code:
AVSValue __cdecl Create_SimpleSample(AVSValue args, void* user_data, IScriptEnvironment* env) { return new SimpleSample(args[0].AsClip(),env); }
__________________
Regards, sh0dan // VoxPod |
11th March 2003, 09:28 | #12 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
Understanding Constructor Problem
@sh0dan
Thanks for correction - maybe you could tell(PM if you want to) me me why we have to have 2 constructor definitions (as least it looks that way to me ) and why you can get away with 1 in other filters as long as it uses parameters So a version 1.0a incorporating the correct colourspace checking now available at http://www.geocities.com/siwalters_u...esample10a.zip regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
11th March 2003, 10:41 | #13 | Link |
Retired
Join Date: Jan 2002
Location: Netherlands
Posts: 1,529
|
Like Belgabor I've also wanted to try my hand at Avisynth filters now and then and like him I've also found it difficult to start because there are hardly any simple examples around.
Now the code that siwalters/sh0dan posted here looks simple enough, but I think what would be useful for a lot of newbie would-be filter writers are comments. And lots of 'em. Mainly why certain things are handled the way they are. Ben's original example is a good one but it only covers a very very small part of Avisynth's internal workings (and I bet a lot of it is outdated by now). I for one am not very good at reading code and understanding what it does right away yet. So comments would help a lot in understanding. |
11th March 2003, 11:45 | #14 | Link |
Retired AviSynth Dev ;)
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
|
I put in very detailed comments to the code.
SimpleSample 1.0b. No code changes - only thing changed is two redundant pointer requests where removed.
__________________
Regards, sh0dan // VoxPod |
11th March 2003, 21:20 | #16 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
@sh0dan
SimpleSample1.0b - Brilliant Do you want to carry on or are you happy for me to do the basics and then you provide the professional touches? regards Simon
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
12th March 2003, 00:11 | #17 | Link |
Simply me
Join Date: Aug 2002
Location: Lancashire, England
Posts: 610
|
SimpleSample 1.1
V1.1 now incorporates sh0dan's planar colourspace code.
Available here http://www.geocities.com/siwalters_u...lesample11.zip Changelog Colourspace check removed from constructor as its not needed. Minor changes to comments (mainly just highlighted the differences between pitch and width.
__________________
http://www.geocities.com/siwalters_uk/fnews.html |
|
|