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 Usage
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th May 2010, 22:54   #1  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 7,816
How to use MT in this script?

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.

Code:
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

Last edited by Atak_Snajpera; 18th May 2010 at 23:11.
Atak_Snajpera is offline   Reply With Quote
Old 19th May 2010, 00:06   #2  |  Link
BigDid
Actually in reserve
 
Join Date: Oct 2004
Posts: 1,605
Quote:
Originally Posted by Atak_Snajpera View Post
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.ph...82#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
__________________
Having a problem with AutoGK? Read & use the FAQ & MORE FAQ first
Want to exchange on AutoGK? try doom10.org
In reserve (inactive) for an undefined period of time.

Last edited by BigDid; 19th May 2010 at 01:18. Reason: Some corrections, thanks to Gavino
BigDid is offline   Reply With Quote
Old 19th May 2010, 00:58   #3  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 7,816
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)

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


If I change to =false then I also get an error (it tells me to change to =true)
Atak_Snajpera is offline   Reply With Quote
Old 19th May 2010, 01:04   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by BigDid View Post
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.
Gavino is offline   Reply With Quote
Old 19th May 2010, 01:12   #5  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Quote:
Originally Posted by Atak_Snajpera View Post
Code:
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

Code:
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.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)

Last edited by Didée; 19th May 2010 at 01:15.
Didée is offline   Reply With Quote
Old 19th May 2010, 01:25   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Atak_Snajpera View Post
now i get this error

If I change to =false then I also get an error (it tells me to change to =true)
Try it like this:
Code:
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.

Last edited by Gavino; 19th May 2010 at 01:28.
Gavino is offline   Reply With Quote
Old 19th May 2010, 01:32   #7  |  Link
BigDid
Actually in reserve
 
Join Date: Oct 2004
Posts: 1,605
Quote:
Originally Posted by Atak_Snajpera View Post
[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


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):

Code:
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
__________________
Having a problem with AutoGK? Read & use the FAQ & MORE FAQ first
Want to exchange on AutoGK? try doom10.org
In reserve (inactive) for an undefined period of time.

Last edited by BigDid; 19th May 2010 at 01:36.
BigDid is offline   Reply With Quote
Old 19th May 2010, 07:55   #8  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,989
Code:
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...
__________________
These are all my personal statements, not those of my employer :)
Blue_MiSfit is offline   Reply With Quote
Old 19th May 2010, 08:17   #9  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
... 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?
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)

Last edited by Didée; 19th May 2010 at 08:20.
Didée is offline   Reply With Quote
Old 19th May 2010, 08:20   #10  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by BigDid View Post
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").

Last edited by Gavino; 19th May 2010 at 11:24.
Gavino is offline   Reply With Quote
Old 19th May 2010, 12:02   #11  |  Link
Nephilis
--preset WTF!
 
Join Date: Feb 2009
Posts: 86
Quote:
Originally Posted by Blue_MiSfit View Post
Code:
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

Code:
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)
Nephilis is offline   Reply With Quote
Old 19th May 2010, 13:47   #12  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Nephilis View Post
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).

Quote:
So that should work
Code:
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.
Gavino is offline   Reply With Quote
Old 19th May 2010, 21:12   #13  |  Link
BigDid
Actually in reserve
 
Join Date: Oct 2004
Posts: 1,605
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
__________________
Having a problem with AutoGK? Read & use the FAQ & MORE FAQ first
Want to exchange on AutoGK? try doom10.org
In reserve (inactive) for an undefined period of time.

Last edited by BigDid; 19th May 2010 at 21:20.
BigDid is offline   Reply With Quote
Old 19th May 2010, 22:06   #14  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
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:

Code:
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?
dansrfe is offline   Reply With Quote
Old 19th May 2010, 23:07   #15  |  Link
Atak_Snajpera
RipBot264 author
 
Atak_Snajpera's Avatar
 
Join Date: May 2006
Location: Poland
Posts: 7,816
Quote:
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!

Quote:
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

Code:
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

Last edited by Atak_Snajpera; 19th May 2010 at 23:23.
Atak_Snajpera is offline   Reply With Quote
Old 21st May 2010, 18:08   #16  |  Link
BigDid
Actually in reserve
 
Join Date: Oct 2004
Posts: 1,605
Quote:
Originally Posted by dansrfe View Post
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.ph...11#post1401011

Did
__________________
Having a problem with AutoGK? Read & use the FAQ & MORE FAQ first
Want to exchange on AutoGK? try doom10.org
In reserve (inactive) for an undefined period of time.
BigDid is offline   Reply With Quote
Old 21st May 2010, 23:19   #17  |  Link
the_provider
Registered User
 
Join Date: Dec 2007
Posts: 25
Quote:
Originally Posted by Gavino View Post
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.

Last edited by the_provider; 23rd May 2010 at 19:59.
the_provider is offline   Reply With Quote
Reply


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 00:19.


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