View Full Version : request a filter
jmac698
9th November 2006, 16:31
I took a look at the C api for avisynth, I think it's simple enough that I could write something. Anyone have any need for a filter that they just can't find anywhere?
Conversely, I hope some experienced coders will help me over the learning curve.
thanks.
Chainmax
9th November 2006, 16:41
Actually, I do. YGPM :).
Prettz
9th November 2006, 22:33
Heheh, how about a spatial denoiser using the Sigma Filter? :) I had to implement that as a project for my Digitial Image Processing class, and I've been wondering whether it would be useful for video filtering. I would sit down and learn how to write an avisynth filter to do it myself, but I don't have any free time.
jmac698
10th November 2006, 01:53
I don't think sigma filter is the best. Before choosing a denoiser, I would survey existing filters to see what has been done already, then choose a better one from research papers, then implement.
http://www.fmrib.ox.ac.uk/~steve/susan/susan/node20.html#SECTION00063100000000000000
I don't agree that this "SUSAN" is always the best, it performs some extra contrast enhancement as a tradeoff.
Fizick
10th November 2006, 05:49
Why C_API? Regular AviSynth plugins API is more common and stable
jmac698
10th November 2006, 15:22
But then I have to do C++, unless you want to tutor me..
sh0dan
10th November 2006, 15:29
@jmac698: You don't have to worry about C++, when you do a "regular" filter - it's all taken care of behind the scenes. You can just write regular C inside the GetFrame() function.
(You do know that C is a subset of C++, right?)
jmac698
11th November 2006, 03:21
ok, and can you think of a simple example that does not use mmx,sseX? With pure C in getframe?
I know it's a subset but I didn't know how freely you could mix the code.
Fizick
11th November 2006, 07:50
Did you see SimpleSample and FilterSDK ?
(sticky thread).
Pookie
11th November 2006, 09:54
If you're still thinking of ideas, I'd like to see an upsizing filter that uses a supersampling or super resolution algo.
http://www.wisdom.weizmann.ac.il/~vision/VideoAnalysis/Demos/SpaceTimeSR/SuperRes_demos.html
http://citeseer.ist.psu.edu/context/845587/0
http://graphics.stanford.edu/courses/cs248-03/samp/samp3.html
Another thing that might be cool is an AVCsource or H264source filter, in the vein of DGdecode.dll or RawSource.Dll. There's always DirectShowSource, but with the advent of HDAVC (or is it AVC-HD?), channels like BBC HD, and the new HD formats on disk, maybe something more focused specifically on h264 could be beneficial. There's the QTinput.dll that has support for h264 Quicktime, but Quicktime only.
Thank you for your consideration.:D
foxyshadis
11th November 2006, 11:24
Your last link looks like little more than an audio oversampling D/A applied to 2D images (no provision for 3D video, as in the first, which is much more interesting). Video is problematic for that because it's of such a low resolution (dimensions and bit depth) that they tend to drown in aliasing - except for the introduction of some random jitter, this is how multi-tap resizers work, after all.
I'm still off and on playing in the area with EEDI2, but I'm still waiting for tritical's upcoming breakthrough arbitrary resize version. :p
MP4Source (since mp4 has a fairly limited number of codecs), or some kind of MplayerSource/FFmpegSource would be hot. Plus ffmpeg is all C. :p
As for the language, since avisynth gives you a pointer to a malloc'd frame buffer, once you have that you can do anything you want with it, with any C/C++/asm syntax, or whatever else you can convince visual studio into compiling. The rest of the boilerplate, like argument checking in the constructor, can be copied out of other plugins. Unfortunately, you must use visual studio in 2.x, the one downside.
Pookie
11th November 2006, 11:38
Your last link looks like little more than an audio oversampling D/A applied to 2D images (no provision for 3D video, as in the first, which is much more interesting). Video is problematic for that because it's of such a low resolution (dimensions and bit depth) that they tend to drown in aliasing - except for the introduction of some random jitter, this is how multi-tap resizers work, after all.
Agreed. I wasn't sure if I was asking for something too complicated or unrealistic in link 1, hence link 3. :p
jmac698
11th November 2006, 23:58
got simplesample thanks..
Chainmax
14th November 2006, 17:58
Did you read my PM? If so, how feasible do you think it is?
jmac698
14th November 2006, 23:06
That is being followed elsewhere
http://forum.doom9.org/showthread.php?t=118264
wonkey_monkey
19th November 2006, 16:24
I'm looking for a filter to do RGB channel mixing, like Photoshop. It would take nine arguments (rr,rg,rb, gr,gg,gb, br,bg,bb) and would do this:
new_r=r*rr+g*rg+b*rb
new_g=r*gr+g*gg+b*gb
new_b=r*br+g*bg+b*bb
The only thing that comes close that I could find was RGBManipulate, but it crashes when I try to use RGBMerge. Is this something you'd like to try creating, jmac?
Alternatively, if anyone knows of an already existing filter to do what I'm after, please let me know.
David
Edited to add: sorry, it looks like I was wrong to use RGBManipulate as AviSynth has it's own versions of these functions since 2.5.6. I can now achieve the effect I was looking for this way, but a channel mixing plugin might still be nice :)
ceboluga
11th December 2006, 18:06
jmac698,
I've got a similar problem as seen on
http://forum.doom9.org/showthread.php?t=90627. My VHS tapes are too old. Somehow the colors got distorted on the original tapes like these:
http://www.syker-fields.kit.net/huegradient-example1.png
http://www.syker-fields.kit.net/huegradient-example2.png
I've tried TweakColor and gradient mask with no good results.
I've tried some features of PhotoShop. My conclusion is: somehow the days of existence of the tapes applied them a hue distortion from left to right. Most of my tapes need a gradual hue correction from +40° in the left to 0° in the center to -40° in the right side.
The filter that seewen and I need must have 4 inputs: lefthue, left%, righthue, right%, where:
left% = the percentage of the screen (left side) that the filter will be applied
right% = as above, but for the right side
left hue = is value to increase/ decrease of the left-most pixel's hue.
right hue = same as above, for the right side.
The effect follows the diagram below:
http://www.syker-fields.kit.net/huegradient-whatitshouldbe.png
Thank you.
Manao
11th December 2006, 19:47
You can try to do that with two masks and mt_merge.
Create one mask for the left hue, white on the left, progressively goin to block black as soon as the left hue is 0. Create another mask for the right hue ( white on the right, black when the right hue is 0 ), then use the following script ( which works in YV12 ) :
lefthued = source.tweak(hue=left_hue)
righthued = source.tweak(hue=right_hue)
source_lefthued = mt_merge(source, lefthued, leftmask, luma=true, u=3, v=3)
result = mt_merge(source_lefthued, righthued, rightmask, luma=true, u=3, v=3)
ceboluga
11th December 2006, 23:47
Very good, Manao!! It worked wonderfully! Here are the results:
http://www.syker-fields.kit.net/mt_merged-example1.png
http://www.syker-fields.kit.net/mt_merged-example2.png
And the final code:
agape = ConverttoYV12 (AVISource("d:\teste.avi"))
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\mt_masktools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\dgbob.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\mipsmooth.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\guavacomb.dll")
lefthued = Tweak(agape,30)
righthued = Tweak(agape,-50)
leftmask = ImageReader ("d:\maskleft.bmp",0,0)
leftmask = Loop(leftmask,Framecount(agape))
leftmask = ConverttoYV12 (leftmask)
rightmask = ImageReader ("d:\maskright.bmp",0,0)
rightmask = Loop(rightmask,Framecount(agape))
rightmask = ConverttoYV12 (rightmask)
source_lefthued = mt_merge(agape, lefthued, leftmask, luma=true, u=3, v=3)
mt_merge(source_lefthued, righthued, rightmask, luma=true, u=3, v=3)
ConvertToYUY2()
DGBob(order=1,mode=0)
GuavaComb(Mode="NTSC",MaxVariation=85,Recall=65,Activation=80)
MipSmooth(preset="VHS")
Thank you!! Now I can see no Hulks in my metal band!!
Ignus2
15th December 2006, 00:01
Using the C++ API, your only option is to use a Microsoft compiler. While Express is free now, and also quite good, some people still tend to prefer other compilers for whatever reason (often practical ones). The C api makes it possible to use your favourite compiler to write avisynth filters.
I have written a couple of filters with the C API. I don't say it was easy to get the hang of it, but it sure was simple afterwards.
jmac698
15th December 2006, 00:49
Do you have source posted? And which compiler did you use? I want to write a plugin soon...
Ignus2
15th December 2006, 01:30
No, I have not yet posted source, as the filters are part of a university project, and they don't really make too much sense individually.
What I have been able to do, is things like
- creating new clip from reading file (source filter)
- modifying existing clip
- take multiple clips as parameters
There are certains things to remember for each scenario. I for example, wouldn't be able to write up a complete filter from scratch, but beause I managed to do it once, so I have written working source, I usually just copy/paste when I write a new filter.
There is an example somewhere written by the original author of the C interface, but it is very vague on comments, and demonstrates only a portion of the api.
I used the GCC compiler with makefiles. 3.4.5 and 4.1.1 also works fine. 4.1.1 also optimizes very decently too.
I'll post what I have gathered so far tomorrow (along with some commented source), after I pass my exam (which in fact, also involves some avs filters :) )
jmac698
15th December 2006, 05:42
that would definitely be useful, thanks (especially the last two functions). and good luck! :)
Ignus2
16th December 2006, 01:38
Here, see attachment.
It's a little example, that uses 2 clips, and "blends" them (writing the result to a new clip). I commented it here and there.
For the devs:
There is a strange behavior of avisynth 2.6 alpha though. See:
LoadCPlugin("cblend.dll")
a = BlankClip(color=$00FF0000)
b = BlankClip(color=$0000FF00)
a = a.PointResize(400,300)
b = b.PointResize(400,300)
CBlend(a,b)
# This crashes on 2.6 alpha
#CBlend(a.PointResize(400,300), b.PointResize(400,300))
It crashes on the second version. I presume that's a bug? I dunno if it's already been fixed or not, though. That's a full script above, does nothing else.
EDIT: The crash was my fault! Whoever downloaded the previous example, please re-download, as the 1st version contained a very serious bug. I'm terribly sorry about this, but it was only recently I realized my fault.
IanB
16th December 2006, 23:32
BlankClip(Width=400, Height=300, color=...2.6 is incomplete, use at your risk!
2.5.6 is the current stable release.
2.5.7RC1 has many fixes and hopefully few regressions (RC2 will be out soon).
Ignus2
17th December 2006, 14:57
I used 2.6, because it has many new things, namely Y8 format and MaskHS()
Does 2.5.7 have those?
Wilbert
17th December 2006, 18:06
Does 2.5.7 have those?
Nope. Just file a bugreport at sourceforge.
Ignus2
8th May 2007, 00:19
In the example.zip I posted above was a very serious bug. I used avs_take_clip() incorrectly, that's why it crashed avisynth 2.6 under certain circumstances.
Whoever downloaded it, please re-download it (example_v2.zip)! Hopefully it is bug-free now.
--
Greets,
I.
jmac698
9th May 2007, 14:38
yay, I wrote my first filter :)
I've been waiting for your example all this time.. it worked fine.
Howto:
1) http://www.mingw.org/download.shtml
get MinGW-3.1.0-1.exe, current/msys (MSYS-1.0.10.exe)
2) install both
3) go into c:\mingw, select all, copy, go into D:\msys\1.0\mingw, paste. Then it should just work.
4) download above example, unzip to c:\, double click msys icon, cd /c/example_v2/example, ... (it may be /c/example depending on your unzip program)
me@COMPUTER1 /c/example_v2/example
$ make
g++ -o cblend.o -c cblend.cpp -O3 -Wall -funroll-loops -Iavisynth_c
g++ -shared -o cblend.dll -s cblend.o -Lavisynth_c -lavisynth_c
(if it works, the prompt will return and it seems like nothing happened, but it did compile),
then copy the resulting cblend.dll to your avisynth plugins and test with the script.
To change your functions name, edit
avs_add_function(env, "myfunctionhere", "cc", create_cblend, 0);
Problems:
If you get compiler errors, such as, "as not found", "begincrt.o not found" "lxxx.lib not found" then you need to find these files in mingw and copy them to msys\1.0\mingw (..\lib etc., look around and guess where they go).
jmac698
9th May 2007, 14:50
Now some questions:
1) How do I write a function for YUV? And I'd really like to know how to copy rgb into v,y,u (yuv in that order). Yes, even though they are different colorspaces. A plugin that does this would suddenly let everyone use the excellent rgb arithmetic tools in yuv space (like mask tools).
2) how do I include two functions in one dll? Can I just copy and paste the sample, change the function names and references, and avs_add_function a different name?
3) What lines do I remove if I don't need to use two input clips?
4) Did you use a better gcc windows package? I know there is another one somewhere...
Ignus2
9th May 2007, 17:01
Well, actually MSYS is not needed. It's enough if you install MinGW, then add "...\MinGW\bin" (by default C:\MinGW\bin) to your PATH environment variable (right click My Comp -> Props. -> Special tab -> Environment variables).
By compiling from MSYS, some things are a bit different, possibly harder, and confusing. I recommend a clean MinGW install without MSYS.
As for the questions:
1) You check at filter creation the input clip format to be YUY2 instead of RGB32, then at frame processing, you treat the BYTE buffer's values to be YUYV instead of BGRA. That will process YUY2 frames.
However, if you want RGB input and YUY2 output, you leave the input check to RGB (avs_is_rgb32()), but you modify the returned clip type, like this (put it at the end of your filter instance creation function):
// Set up returned clip VideoInfo
fi->vi.pixel_type = AVS_CS_YUY2;
2) Right. You can add as many functions as you want.
3) The ones that have the word clip2 around it :)
--
Greets,
I.
foxyshadis
9th May 2007, 23:41
Beware of playing fast and loose with avisynth's colorspaces; if anything has to allocate a new frame, you'll lose a good chunk of whatever was stored in the chroma planes since they're only quarter-size for YV12. (Masktools won't work with YUY2.)
If you switch to avisynth 2.6 you can just throw everything into YV24 though; masktools should work as-is, though I don't recall. There's no RGB planar yet, maybe Ian will be gracious enough to add it eventually.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.