View Full Version : How to use MT in this script?
Atak_Snajpera
18th May 2010, 22:54
I need to speed up this script. I tried SetMTMode but it does not change anything in terms of speed. So now I thinking about using MT function however I have no idea how to do it.
video=DSS2("video.mkv")
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
a = selectevery(video,8, 0)
b = selectevery(video,8, 1)
c = selectevery(video,8, 2)
d = selectevery(video,8, 3)
e = selectevery(video,8, 4)
f = selectevery(video,8, 5)
g = selectevery(video,8, 6)
h = selectevery(video,8, 7)
ab = merge(a,b,0.5)
cd = merge(c,d,0.5)
ef = merge(e,f,0.5)
gh = merge(g,h,0.5)
abcd = merge(ab,cd,0.5)
efgh = merge(ef,gh,0.5)
video = merge(abcd,efgh,0.5)
return video
BigDid
19th May 2010, 00:06
I need to speed up this script. I tried SetMTMode but it does not change anything in terms of speed. So now I thinking about using MT function however I have no idea how to do it.
Hi Atak,
From scratch:
http://avisynth.org/mediawiki/MT_support_page
and/or
http://avisynth.org/mediawiki/MT
No time to test the resulting but you can go this path:
1/ use MT("...") for every line and test 1 line after another
ex: MT("super = MSuper(video)")
MT("backward_vec = MAnalyse(super, isb = true)")
2/
a/use MT with triple quotes whenever the inside function uses simple quotes;
ex: MT("""video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)""")
b/ MT with single or triple quotes can be used for multiples lines (verify that MT line by line is working before attempting multiple lines); triple quotes is, however, more flexible.
ex: MT("""
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
""")
3/
a/Whenever MTing frames results can have 1 or more horizontal jaggied lines; overlap needs to be increased to 4 or more.
Ex same as above:
MT("""
...
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
""", overlap=4)
b/ see also this post and following for preferred version (SET 2.58):
http://forum.doom9.org/showthread.php?p=1390182#post1390182
I, for one, would be very happy if you can get a reliable MTing use in Ripbot cause using an outside avs as source with heavy MT inside can be a pain atm.
Did
Atak_Snajpera
19th May 2010, 00:58
video=DSS2("video.mkv")
video.mt("""
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
return video
""",2,0,splitvertical=true)
a = selectevery(video,8, 0)
b = selectevery(video,8, 1)
c = selectevery(video,8, 2)
d = selectevery(video,8, 3)
e = selectevery(video,8, 4)
f = selectevery(video,8, 5)
g = selectevery(video,8, 6)
h = selectevery(video,8, 7)
ab = merge(a,b,0.5)
cd = merge(c,d,0.5)
ef = merge(e,f,0.5)
gh = merge(g,h,0.5)
abcd = merge(ab,cd,0.5)
efgh = merge(ef,gh,0.5)
video = merge(abcd,efgh,0.5)
return video
now i get this error
http://img20.imageshack.us/img20/131/scriptavssnapshot000120.png
If I change to =false then I also get an error (it tells me to change to =true)
Gavino
19th May 2010, 01:04
a/use MT with triple quotes whenever the inside function uses variables/numbers and/or simple quotes;
ex: MT("""video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)""")
b/ MT with triple quotes can be used for multiples lines
Triple quotes are only required if the inside function itself contains (simple) quotes - variables/numbers are irrelevant.
Triple quotes are not required for multiple lines, simple quotes work too, although it's a good practice to use triple quotes as then you don't need to worry if you have (simple) quotes inside, or add them later.
I will add some further general advice:
- don't use MT for filters that don't actually process any pixel data and merely select frames (eg Trim, SelectEvery) as it will be slower with MT than without.
Didée
19th May 2010, 01:12
a = selectevery(video,8, 0)
b = selectevery(video,8, 1)
c = selectevery(video,8, 2)
d = selectevery(video,8, 3)
e = selectevery(video,8, 4)
f = selectevery(video,8, 5)
g = selectevery(video,8, 6)
h = selectevery(video,8, 7)
ab = merge(a,b,0.5)
cd = merge(c,d,0.5)
ef = merge(e,f,0.5)
gh = merge(g,h,0.5)
abcd = merge(ab,cd,0.5)
efgh = merge(ef,gh,0.5)
video = merge(abcd,efgh,0.5)
That's a little cumbersome. Find the Average.dll plugin, then do
w = 1./8.
Average(a,w, b,w, c,w, d,w, e,w, f,w, g,w, h,w)
Much faster, and much better precision.
Gavino
19th May 2010, 01:25
now i get this error
http://img20.imageshack.us/img20/131/scriptavssnapshot000120.png
If I change to =false then I also get an error (it tells me to change to =true)
Try it like this:
video=DSS2("video.mkv")
video = video.mt("""
super = MSuper()
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
MFlowFps(super, backward_vec, forward_vec, num=200, den=1, ml=100)
""",2,0,splitvertical=false)
I suggest splitvertical=false as most motion tends to be horizontal.
You probably also need to use a non-zero overlap for best results too, as otherwise the motion analysis will stop where mt splits the frame.
BigDid
19th May 2010, 01:32
[CODE]video=DSS2("video.mkv")
video.mt("""
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
return video
""",2,0,splitvertical=true)
now i get this error
http://img20.imageshack.us/img20/131/scriptavssnapshot000120.png
If I change to =false then I also get an error (it tells me to change to =true)
Yep,
This works (no "video" variable inserted):
mt("""
super = MSuper()
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
MFlowFps(super, backward_vec, forward_vec, num=200, den=1, ml=100)
""",2,0)
Edit: Gavino was quicker, inserting some variables is tricky, Gavino has mastered this MT-scripting not me, so whenever possible I get rid of any extra variable (for MTing)
Did
Blue_MiSfit
19th May 2010, 07:55
video=DSS2("video.mkv")
MT("""
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
""", 2,0)
a = selectevery(video,8, 0)
b = selectevery(video,8, 1)
c = selectevery(video,8, 2)
d = selectevery(video,8, 3)
e = selectevery(video,8, 4)
f = selectevery(video,8, 5)
g = selectevery(video,8, 6)
h = selectevery(video,8, 7)
ab = merge(a,b,0.5)
cd = merge(c,d,0.5)
ef = merge(e,f,0.5)
gh = merge(g,h,0.5)
abcd = merge(ab,cd,0.5)
efgh = merge(ef,gh,0.5)
video = merge(abcd,efgh,0.5)
return video
That should work...
Didée
19th May 2010, 08:17
... and when you have it up & running, watch out carefully for oddities in the middle of the frame. Of all MV** functions, MVFlow** should be the most sensitive when it comes to slicing artifacts.
For 'denoising' purposes based on compensation, the drawback mostly is just reduced efficiency around the slice borders. But when interpolating new frames, true visual artifacts are to be expected. (Can't follow motion across slice boundaries -> can not synthesize any motion that crosses slice boundaries.)
I'd suggest to look somewhat deeper into getting SetMTmode work like expected. Also, don't forget Josey's "Multi" version of MVTools, which can/will use multithreading internally/natively, instead of brute-force-work-around-ing same from external.
Lastly, MVTools actually is offering internal filters for creating motion blur ... any particular reason to build it up all manually?
Gavino
19th May 2010, 08:20
inserting some variables is tricky
The key to understanding this aspect is that MT works like this:
1. The input clip is split (by cropping) into the appropriate parts, according to the number of threads, vertical/horizontal flag and overlap.
2. For each part-clip in turn, the clip is assigned to 'last' and the filter or filter-chain (ie the part in quotes) is evaluated. At run-time, each of these parts is run in a separate thread.
3. The results from each part are joined together and returned as the result of MT.
The second point is important here.
For MT to work properly, the inner filter (or chain) must be written to use 'last' as its input. (Normally this use of 'last' is implicit, ie the filter is called without an explicit input clip.) So
mt("""
super = MSuper()
...""", ...)
works (as long as 'last' is defined before the call to mt). MSuper will be called on slices of 'last'.
video.mt("""
super = MSuper()
...""", ...)
also works; 'video' is the input to mt and MSuper is called on slices of 'video'.
But Atak_Snajpera's original
video.mt("""
super = MSuper(video)
...""", ...)
does not work because MSuper is called on 'video' instead of 'last', so the filter for each slice returns the full video, leading to error messages about changing the height or width.
Blue_MiSfit's
MT("""
super = MSuper(video)
...""", ...)
fails for the same reason (or would do, but since 'last', the defaulted input to mt, is not defined before the call, it fails with "invalid arguments to function mt").
Nephilis
19th May 2010, 12:02
video=DSS2("video.mkv")
MT("""
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
""", 2,0)
a = selectevery(video,8, 0)
b = selectevery(video,8, 1)
c = selectevery(video,8, 2)
d = selectevery(video,8, 3)
e = selectevery(video,8, 4)
f = selectevery(video,8, 5)
g = selectevery(video,8, 6)
h = selectevery(video,8, 7)
ab = merge(a,b,0.5)
cd = merge(c,d,0.5)
ef = merge(e,f,0.5)
gh = merge(g,h,0.5)
abcd = merge(ab,cd,0.5)
efgh = merge(ef,gh,0.5)
video = merge(abcd,efgh,0.5)
return video
That should work...
That should not work because video returns nothing in MT("""..""",..)
So that should work
video=DSS2("video.mkv")
MT("""
super = video.MSuper()
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
return video
""", 2,0)
Gavino
19th May 2010, 13:47
That should not work because video returns nothing in MT("""..""",..)
You're right about that, although Blue_MiSfit's script was already wrong for at least two other reasons I noted above (and a fourth I've just noticed now).
So that should work
video=DSS2("video.mkv")
MT("""
super = video.MSuper()
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=200, den=1, ml=100)
return video
""", 2,0)
No, as I explained, MSuper must be applied to 'last', not 'video'.
Further (the 'fourth' reason), the result of mt must also be assigned to 'video', since it is needed later in the script. Doing the assignment inside MT assigns only one 'slice' of the result to 'video'.
So it should be done as I showed in post #6.
BigDid
19th May 2010, 21:12
Hi,
Thanks to Gavino for taking the time to share some knowledge about avisynth and MTing, I appreciate.
Also thanks to Didée for is technical comments (even if usually too brillant for me). I can catch some glimpse from time to time :)
@ Atak: is your script working?
Any speed improvement?
Did
dansrfe
19th May 2010, 22:06
I hope this is close enough to the topic to fit in this thread but is there a way to prevent MT from creating a "spliced noise line" right in the middle of the frame if used like this:
MT("""
super = MSuper(pel=2, sharp=1)
backward_vec2 = super.MAnalyse(isb = true, delta = 2, overlap=4, blksize=16,chroma=false)
backward_vec1 = super.MAnalyse(isb = true, delta = 1, overlap=4, blksize=16,chroma=false)
forward_vec1 = super.MAnalyse(isb = false, delta = 1, overlap=4, blksize=16,chroma=false)
forward_vec2 = super.MAnalyse(isb = false, delta = 2, overlap=4, blksize=16,chroma=false)
MDegrain2(super, backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=200)
""",2)
Also for 23.976 progressive video I heard about a modification of the MDegrain script that is better used for progressive video?
Atak_Snajpera
19th May 2010, 23:07
I'd suggest to look somewhat deeper into getting SetMTmode work like expected. Also, don't forget Josey's "Multi" version of MVTools, which can/will use multithreading internally/natively, instead of brute-force-work-around-ing same from external.
When I replaced lame "merges" with Average plugin bottleneck suddenly disappeared with SetMtMode! So I don't have to use MT at all and also speed is alot better. Another nice thing is that Average indeed gives noticeably better quality. It is so good that I can reduce number of interpolated frames by half!
Lastly, MVTools actually is offering internal filters for creating motion blur ... any particular reason to build it up all manually?
Last time I tried It didn't give me correct motionblur. http://forum.doom9.org/showthread.php?t=143977
To all. Big thanks for explaining me how to use MT with variable!
My final script for 1/100 -> 1/25 shutter emulation
SetMTMode(5,0)
video=DSS2("C:\temp\AVCHD2Intratemp\001-00000\video.mkv")
SetMTMode(2)
super = MSuper(video)
backward_vec = MAnalyse(super, isb = true)
forward_vec = MAnalyse(super, isb = false)
video=MFlowFps(video, super, backward_vec, forward_vec, num=100, den=1, ml=100)
a = selectevery(video,4, 0)
b = selectevery(video,4, 1)
c = selectevery(video,4, 2)
d = selectevery(video,4, 3)
w = 1.0/4.0
video = Average(a,w, b,w, c,w, d,w)
return video
BigDid
21st May 2010, 18:08
I hope this is close enough to the topic to fit in this thread but is there a way to prevent MT from creating a "spliced noise line" right in the middle of the frame if used like this:...
Hi,
Already answered: increase overlap from 4 to 8 or more; see 3/
http://forum.doom9.org/showthread.php?p=1401011#post1401011
Did
the_provider
21st May 2010, 23:19
The key to understanding this aspect is that MT works like this:....
Greetings.
I copied from another thread a script containing:
#Denoiser script for interlaced video
Loadplugin("C:\Program Files\AviSynth 2.5\plugins\MVTools\mvtools2.dll")
loadPlugin("c:\Program Files\AviSynth 2.5\plugins\CNR\Cnr2.dll")
loadPlugin("c:\Program Files\AviSynth 2.5\plugins\MT.dll")
SetMTMode(5)
#Modify this line to point to your video file
source=AVISource("E:\Disney Films\Oscars0009.avi").killaudio()
SetMTMode(2,0)
chroma=source.Cnr2("oxx",8,16,191,100,255,32,255,false) #VHS
#chroma=source.Cnr2("oxx",8,14,191,75,255,20,255,false) #Laserdisc
output=MDegrain2i2(chroma,0,0)
#stackhorizontal(source,output)
return output
function MDegrain2i2(clip source, int "overlap", int "dct")
{
overlap=default(overlap,0) # overlap value (0 to 4 for blksize=8)
dct=default(dct,0) # use dct=1 for clip with light flicker
fields=source.SeparateFields() # separate by fields
super = fields.MSuper()
backward_vec2 = super.MAnalyse(isb = true, delta = 2, overlap=overlap, dct=dct)
forward_vec2 = super.MAnalyse(isb = false, delta = 2, overlap=overlap, dct=dct)
backward_vec4 = super.MAnalyse(isb = true, delta = 4, overlap=overlap, dct=dct)
forward_vec4 = super.MAnalyse(isb = false, delta = 4, overlap=overlap, dct=dct)
fields.MDegrain2(super, backward_vec2,forward_vec2,backward_vec4,forward_vec4,thSAD=400)
Weave()
}
And last version from avisynth returns:
Script error: there is no function caller Super...
Any advice for that?
Thank you in advance.
Best regards.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.