PDA

View Full Version : internal vdub filters in AVIsynth


Wizal
25th May 2002, 18:30
Sorry for the dumb question but is there any way to use an internal VirtualDub filter in AVIsynth (for instance General Convolution) ? That's because I need to place it between Telecide() and Decimate(), and I don't find any way to do that :(

Acaila
25th May 2002, 20:50
You'll need this (http://forum.doom9.org/showthread.php?s=&threadid=23804) file. But the General Convolution filter isn't in there yet, so you'll have to write the script yourself (which can be a pain).

If you ever get it to work, please post the script in this forum so we can all use it :)

And could you explain that particular filter to me? I've always had the feeling it could be quite usefull (or the General Convolution 3D filter which I've got lying around somewhere too), but I've never managed to understand the theory behind how it works.

Wizal
25th May 2002, 21:28
You'll need this file. But the General Convolution filter isn't in there yet, so you'll have to write the script yourself (which can be a pain).
From what I understand, this only works with external filters (which you can import in AVISynth) and the file you point out is basically just a front-end script to use them more easily. The problem is the General Convolution filter is Internal to VirtualDub (there is no .vdf file), so I don't have a clue about how to access it with AVISynth.

And could you explain that particular filter to me? I've always had the feeling it could be quite usefull (or the General Convolution 3D filter which I've got lying around somewhere too), but I've never managed to understand the theory behind how it works.
Basically you have a 3x3 matrix, the center beeing the destination pixel processed.

*the following matrix
0 0 0
0 256 0
0 0 0
will result with no process at all (destination pixel is 256/256 of source pixel)

*the following matrix
28 29 28
29 28 29
28 29 28
will result in a 3x3 blur destination pixel is the sum of all source pixels multiplied by either 28 or 29, and then divided by 256 (I say 28 or 29 because 256 is not dividable by 9)

*the following matrix
0 0 0
0 128 0
0 0 0
will just diminish intensity by half

So you see it's a general filter allowing you to manually do lot of things, but of course most of the interesting stuff already exist in separate and more optimized filters.

In fact the main interest I have in this filter is the following matrix:

0 51 0
51 52 51
0 51 0

which allow me to sort out a specific case where my source image got all pixels right for luma but where only half the pixels have chroma data (resulting in a nasty 2x2 color noise grid). The filter thus allow me to correct it while keeping a better sharpness than a pure 3x3 box blur.

Of course the problem with this solution is by correcting the chroma I also loose some luma resolution, which is quite stupid since the data are in fact existing and correct in the source, unfortunately I haven't found a way yet to apply the general convolution filter only to chroma (see my other thread).

Acaila
26th May 2002, 10:01
Well, I have this General Convolution 3D filter plugin, which does exactly the same thing as the standard General Convolution filter except you can also adjust the matrix of the two previous frames. And the matrix has increased from 3x3 to 5x5. Using this you CAN import it into Avisynth with a script.
You can find it here (http://home.bip.net/gunnart/video/).

However I have no idea on how to apply something to only the UV portion of a frame. There's a few smoothers out there that can smooth Y and UV seperately (I found more than I thought I would), but none that can split it up so you can apply your own filter to either side.

And thank you for explaining this filter to me. I understand it a lot better now :).

Wizal
26th May 2002, 20:09
Very nice filter, I never saw it before, thanks a lot

Wizal
27th May 2002, 02:24
Unfortunately I'm having troubles writing a front-script for AVISynth because of the crazy amount of parameters involved : AVISynth doesn't accept 76 parameters in a function apparently :(

Wilbert
30th May 2002, 10:15
I also looked at it. Of course you can also use 2*25+9+1=60 arguments instead (that is restrictive, but not too much). But what I don't know is how to concatenate all those strings/integers. For example:

arguments: str1 = 001, str2 = 002

str3 = "str1 8 str2" (a string of the form 0018002)

How do you program that?

Acaila
30th May 2002, 12:32
I haven't looked at it yet, but I'll give it a shot when I get home.

Acaila
30th May 2002, 20:38
It has me puzzled as well. I have no idea on how to concatenate strings either. I tried a LOT of different syntaxes, but none of them worked.

There were a few people with REALLY impressive scripts a while back. However all threads before the beginning of this month have been purged, so I can't remember who they were.

If any Avisynth guru's are reading this, feel free to jump in :)

dividee
31st May 2002, 00:08
Concatenating string is easy, just use the "+" operator:
s1="A"
s2="B"
s=s1+s2+"C" # s="ABC"

Unfortunately, there is no way I know of for converting an integer to a string. I might add one if you need it.

Acaila
31st May 2002, 08:46
Sorry, I didn't mean string, I meant integer (hexadecimal integers in this case). :)

Wilbert
31st May 2002, 10:10
@dividee

I guess the preroll argument must be two here, no?

@all

What's wrong with the following:

You define your function

VD_3d...(0, some boolean, int "s1", int "s2", ...)

concatenating the integers and turning it into a string:

w = "s1" + "8" + "s2" + etc.

I guess this should work. Maybe the problem is that an integer 001
reduces to 1 (you need those zeros in the string w). In that case you can also use strings as inputs thus

VD_3d...(0, some boolean, string "s1", string "s2", ...)

and defining the string

w = s1 + "8" + s2 + etc.

Tomorrow I have some time to try this.

Acaila
31st May 2002, 11:07
VD_3d...(0, some boolean, int "s1", int "s2", ...)
concatenating the integers and turning it into a string:
w = "s1" + "8" + "s2" + etc.
In this case the "s1" and "s2" will be recognized as 's1' and 's2', and not substituted with their value.
So you'll end up with w = "s18s2".
And if you drop the "" they will end up being added up, not concatenated.

VD_3d...(0, some boolean, string "s1", string "s2", ...)
and defining the string:
w = s1 + "8" + s2 + etc.
Haven't tried that one before, good idea :).
Hopefully Avisynth won't ignore that you define them as string and just add all the values....

Wilbert
1st June 2002, 19:53
Well, here it is:

################################################
# GeneralConvolution3D v1.1, by Gunnar Thalin #
# #
# The last matrix (matrix for frame prior to #
# previous) has to be inserted manually (only #
# when one of its arguments is non-zero) #
# since a function can have 60 arguments at #
# maximum. #
# #
# 1) matrix entries: (0-256) #
# #
# 2) matrix for current frame: a11-a55 #
# #
# 3) matrix for previous frame: b11-b55 #
# #
# 4) The matrix entries have to be inserted in #
# hexadecimal notation. Thus for example: #
# 51 decimal = 3*16^1 + 3*16^0 hexadecimal = #
# = 33 hexadecimal. #
# #
# 5) a33 = 256 decimal = 1*16^2 hexadecimal #
# = 100 hexadecimal leaves the clip unchanged. #
# #
# 6) The matrix entries must be a three digit #
# number, insert zeros from the left when #
# necessary. #
################################################

global VirtualDub_plugin_directory = "c:\virtualdub\plugins"

function VD_GeneralConvolution3D(clip clip, string "mode", string "a11", string "a12", string "a13", string "a14",
\ string "a15", string "a21", string "a22", string "a23", string "a24", string "a25", string "a31", string "a32",
\ string "a33", string "a34", string "a35", string "a41", string "a42", string "a43", string "a44", string "a45",
\ string "a51", string "a52", string "a53", string "a54", string "a55", string "b11", string "b12", string "b13",
\ string "b14", string "b15", string "b21", string "b22", string "b23", string "b24", string "b25", string "b31",
\ string "b32", string "b33", string "b34", string "b35", string "b41", string "b42", string "b43", string "b44",
\ string "b45", string "b51", string "b52", string "b53", string "b54", string "b55")
{
LoadVirtualdubPlugin(VirtualDub_plugin_directory+"\GeneralConvolution3D.vdf", "_VD_GeneralConvolution3D", 1)
mode = default(mode, "input")
mode = (mode=="input") ? 0 : (mode=="output") ? 1 : -1
Assert(mode>=0, """VD_GeneralConvolution3D: "mode" parameter must be "input" or "output"""")
a11 = default(a11, "000")
a12 = default(a12, "000")
a13 = default(a13, "000")
a14 = default(a14, "000")
a15 = default(a15, "000")
a21 = default(a21, "000")
a22 = default(a22, "000")
a23 = default(a23, "000")
a24 = default(a24, "000")
a25 = default(a25, "000")
a31 = default(a31, "000")
a32 = default(a32, "000")
a33 = default(a33, "046")
a34 = default(a34, "000")
a35 = default(a35, "000")
a41 = default(a41, "000")
a42 = default(a42, "000")
a43 = default(a43, "000")
a44 = default(a44, "000")
a45 = default(a45, "000")
a51 = default(a51, "000")
a52 = default(a52, "000")
a53 = default(a53, "000")
a54 = default(a54, "000")
a55 = default(a55, "000")
b11 = default(b11, "000")
b12 = default(b12, "000")
b13 = default(b13, "000")
b14 = default(b14, "000")
b15 = default(b15, "000")
b21 = default(b21, "000")
b22 = default(b22, "000")
b23 = default(b23, "000")
b24 = default(b24, "000")
b25 = default(b25, "000")
b31 = default(b31, "000")
b32 = default(b32, "000")
b33 = default(b33, "000")
b34 = default(b34, "000")
b35 = default(b35, "000")
b41 = default(b41, "000")
b42 = default(b42, "000")
b43 = default(b43, "000")
b44 = default(b44, "000")
b45 = default(b45, "000")
b51 = default(b51, "000")
b52 = default(b52, "000")
b53 = default(b53, "000")
b54 = default(b54, "000")
b55 = default(b55, "000")
# "matrix for frame prior to previous" elements:
c11 = "000"
c12 = "000"
c13 = "000"
c14 = "000"
c15 = "000"
c21 = "000"
c22 = "000"
c23 = "000"
c24 = "000"
c25 = "000"
c31 = "000"
c32 = "000"
c33 = "000"
c34 = "000"
c35 = "000"
c41 = "000"
c42 = "000"
c43 = "000"
c44 = "000"
c45 = "000"
c51 = "000"
c52 = "000"
c53 = "000"
c54 = "000"
c55 = "000"
str = "8"+a11+"8"+b11+"8"+c11 + "8"+a12+"8"+b12+"8"+c12 + "8"+a13+"8"+b13+"8"+c13 + "8"+a14+"8"+b14+"8"+c14 +
\ "8"+a15+"8"+b15+"8"+c15 + "8"+a21+"8"+b21+"8"+c21 + "8"+a22+"8"+b22+"8"+c22 + "8"+a23+"8"+b23+"8"+c23 +
\ "8"+a24+"8"+b24+"8"+c24 + "8"+a25+"8"+b25+"8"+c25 + "8"+a31+"8"+b31+"8"+c31 + "8"+a32+"8"+b32+"8"+c32 +
\ "8"+a33+"8"+b33+"8"+c33 + "8"+a34+"8"+b34+"8"+c34 + "8"+a35+"8"+b35+"8"+c35 + "8"+a41+"8"+b41+"8"+c41 +
\ "8"+a42+"8"+b42+"8"+c42 + "8"+a43+"8"+b43+"8"+c43 + "8"+a44+"8"+b44+"8"+c44 + "8"+a45+"8"+b45+"8"+c45 +
\ "8"+a51+"8"+b51+"8"+c51 + "8"+a52+"8"+b52+"8"+c52 + "8"+a53+"8"+b53+"8"+c53 + "8"+a54+"8"+b54+"8"+c54 +
\ "8"+a55+"8"+b55+"8"+c55
return clip._VD_GeneralConvolution3D(0, mode, str)
}

# example:
# ConvertToRGB()
# VD_GeneralConvolution3D("output","000","000","000","000","000",
# \ "000","000","033","000","000",
# \ "000","033","034","033","000",
# \ "000","000","033","000","000",
# \ "000","000","000","000","000")
# ConvertToYUY2()

Does anyone know a good set of default values?

Acaila
1st June 2002, 20:07
Way to go :)

Wizal
1st June 2002, 20:13
Impressive ! Thanks dude :)