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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 9th March 2003, 23:59   #1  |  Link
Belgabor
VDubMod Devel
 
Belgabor's Avatar
 
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
Belgabor is offline   Reply With Quote
Old 10th March 2003, 00:33   #2  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 10th March 2003, 00:37   #3  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
I am so tempted to say "Simple Simon".

Isn't there the Invert sample at avisynth.org, or was it sh0dan's home page? That's where everyone starts. After that, there is SO MUCH source available for study.
Guest is offline   Reply With Quote
Old 10th March 2003, 05:00   #4  |  Link
Richard Berg
developer wannabe
 
Richard Berg's Avatar
 
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.
Richard Berg is offline   Reply With Quote
Old 10th March 2003, 05:10   #5  |  Link
trbarry
Registered User
 
trbarry's Avatar
 
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
trbarry is offline   Reply With Quote
Old 10th March 2003, 08:39   #6  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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
sh0dan is offline   Reply With Quote
Old 10th March 2003, 12:41   #7  |  Link
Belgabor
VDubMod Devel
 
Belgabor's Avatar
 
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
Belgabor is offline   Reply With Quote
Old 10th March 2003, 21:39   #8  |  Link
Si
Simply me
 
Si's Avatar
 
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

Last edited by Si; 7th May 2006 at 08:11.
Si is offline   Reply With Quote
Old 11th March 2003, 00:12   #9  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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");
}
(Also changed YV12 to planar, so that possible future planar formats also will fail). You should perhaps also do a planar version

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
[...]
As GetRowSize(PLANAR_U) will return 0 on non-planar images, nothing will be done in these loops, if the image is interleaved (RGB or YUY2).
__________________
Regards, sh0dan // VoxPod

Last edited by sh0dan; 11th March 2003 at 00:22.
sh0dan is offline   Reply With Quote
Old 11th March 2003, 00:43   #10  |  Link
Si
Simply me
 
Si's Avatar
 
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");
}
doesn't compile on my system.
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.
Si is offline   Reply With Quote
Old 11th March 2003, 08:32   #11  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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");
}
and
Code:
AVSValue __cdecl Create_SimpleSample(AVSValue args, void* user_data, IScriptEnvironment* env) {
    return new SimpleSample(args[0].AsClip(),env);
}
You know when it is a contructor, because it is called the same as the class you are modifying, and it does return any values (not even void).
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 11th March 2003, 09:28   #12  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 11th March 2003, 10:41   #13  |  Link
Acaila
Retired
 
Acaila's Avatar
 
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.
Acaila is offline   Reply With Quote
Old 11th March 2003, 11:45   #14  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
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
sh0dan is offline   Reply With Quote
Old 11th March 2003, 12:02   #15  |  Link
Acaila
Retired
 
Acaila's Avatar
 
Join Date: Jan 2002
Location: Netherlands
Posts: 1,529
Thank you, sh0dan. This helps a lot
Acaila is offline   Reply With Quote
Old 11th March 2003, 21:20   #16  |  Link
Si
Simply me
 
Si's Avatar
 
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
Si is offline   Reply With Quote
Old 12th March 2003, 00:11   #17  |  Link
Si
Simply me
 
Si's Avatar
 
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.
Si is offline   Reply With Quote
Old 12th March 2003, 00:22   #18  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Nice - nothing to add from here
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 12th March 2003, 10:39   #19  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
Quote:
Available here (...)
Results in page not available?
Wilbert is offline   Reply With Quote
Old 12th March 2003, 11:47   #20  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
Copy the URL into a new browser window.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 13:47.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.