Log in

View Full Version : Trims and variables not working


Dogway
10th November 2010, 05:30
Hello, I need to optimize a script where I call several trims for custom filtering. I would like to know how can I call them in a simple way and if possible in a less demanding RAM.

source-at-25fps...

a=trim(1,85).interleave(\
selectevery(5,0)\
,selectevery(5,1)\
,selectevery(5,2)\
,selectevery(5,3).GeneralConvolution(0, "
0 0 0
0 1 0
0 1 0 ")\
,selectevery(5,4).GeneralConvolution(0, "
0 0 0
0 1 0
0 1 0 "))


b=trim(86,146).interleave(\
selectevery(5,0)\
,selectevery(5,1).GeneralConvolution(0, "
0 1 0
0 1 0
0 0 0 ")\
,selectevery(5,2).GeneralConvolution(0, "
0 1 0
0 1 0
0 0 0 ")\
,selectevery(5,3)\
,selectevery(5,4))...

a+b....

This makes my custom filtering not work and an output of 150fps (I also tried Trim(a,1,85)+...) But if I write:
trim()
interleave....
then it works but I cant wrap them into a variable.

IanB
10th November 2010, 06:52
Doh!...
Last=Last
a=Last.trim(1,85).interleave(\
Last.selectevery(5,0)\
,Last.selectevery(5,1)\
,Last.selectevery(5,2)\
,Last.selectevery(5,3).GeneralConvolution(0, "
...

creaothceann
10th November 2010, 07:12
Write a function, for example like this:

# source-at-25fps...

str_a = "
0 0 0
0 1 0
0 1 0 "

str_b = "
0 1 0
0 1 0
0 0 0 "

a = filter( 1, 85, str_a, b4=true, b5=true)
b = filter(86, 146, str_b, b2=true, b3=true)
a + b




function filter(clip c, int index1, int index2, string s, bool "b1", bool "b2", bool "b3", bool "b4", bool "b5") {
c.Trim(index1, index2)
v1 = default(b1, false) ? selectevery(5, 0).GeneralConvolution(0, s) : selectevery(5, 0)
v2 = default(b2, false) ? selectevery(5, 1).GeneralConvolution(0, s) : selectevery(5, 1)
v3 = default(b3, false) ? selectevery(5, 2).GeneralConvolution(0, s) : selectevery(5, 2)
v4 = default(b4, false) ? selectevery(5, 3).GeneralConvolution(0, s) : selectevery(5, 3)
v5 = default(b5, false) ? selectevery(5, 4).GeneralConvolution(0, s) : selectevery(5, 4)
interleave(v1, v2, v3, v4, v5)
}

Gavino
10th November 2010, 10:19
a=trim(1,85).interleave(\
selectevery(5,0)\
,selectevery(5,1)\
...

is equivalent to
a = interleave(trim(1,85), selectevery(5,0), selectevery(5,1), ...)

which is why you get 150fps (6x25).

creaothceann's solution is the neatest way to do this sort of thing.
If you find yourself repeating similar bits of script, abstract the processing into a function.

Didée
10th November 2010, 11:17
Better don't use GeneralConvolution for such a simple task. It is overall slow, and requires colorspace conversion from YUV to RGB and back again.

"Abusing" mt_edge from MaskTools:

mt_edge("0 0 0 0 1 0 0 1 0 2",0,255,0,255,U=2,V=2)


The "general" way, via Avisynth's resizers:

E.g.: spline36resize(width,height,0,-0.5,width,height)


Much faster (7-to-10-fold), and less ressources.


Also, don't call the shifting function for each and every of the snipplets. Calling one filter a few hundred times probably is what eats your RAM away.
Create *one time* an up-shifted clip, *one time* a down-shifted clip, and use the building chain only for splicing.

Dogway
10th November 2010, 19:44
Thanks, there is a lot I can learn from this.

Didée: I will be using mt_edge instead, but with UV=3, it looks chroma is also shifted. That other way is also good, but Im going to stick to this one for now while everything runs fine.