MT support page
From Avisynth
Contents |
[edit] What is Avisynth MT
[edit] Introduction
Avisynth MT (MT stands for Multi-Threaded) consists of two components:
- A modified version of Avisynth that makes the Avisynth API thread safe. It also includes the two functions SetMTMode() and GetMTMode().
- A filter MT() that splits a frame in smaller parts and let each thread work on each part.
Additional information material about Avisynth MT can be found following the links below:
- Technical Info : in the MT Wiki page
- General Discussion : in the related doom9 forum thread (94996)
- Technical Discussion : in the related doom9 forum thread (95596)
[edit] Revisions
- 0.7 modified 2.5.7.5 avisynth.dll [1]
- modified 2.5.7.4 avisynth.dll [2]
- 0.6 modified 2.5.7.3 avisynth.dll [3]
- 0.5 modified 2.56 avisynth.dll [4]
- 0.41 [5]
[edit] MT usage
not the cpu utilization.
Syntax
- See general Avisynth syntax
Installation
- Copy mt.dll into the avisynth plugin directory and copy the included avisynth.dll into your windows\system32 directory or where avisynth.dll is located and remember to take a backup of the old avisynth.dll(rename it or something) if you don't have version 2.6 installed.
- Modified avisynth 2.5.7.5 - It contains the two new functions SetMTMode() and GetMTMode() and is needed by MT.dll. Install it by overwriting avisynth.dll in your c:\windows\system32 (and remember to take a backup of the old file first)
[edit] Differences between MT() and SetMTMode()
The differences between MT()and SetMTMode() are explained by foxyshadis in this doom9 forum post. The two images below show how MT() and SetMTmode() processes frames differently. The green part of the frame is processed by thread 1 and the red part by thread 2
[edit] MT() related
MT Syntax:
MT(clip clip, string filter, int threads, int overlap, bool splitvertical)
All parameters are named.
Filter parameters:
clip clip = last
input clip
filter string = No default
filter to run multithreaded. Note that the filter must not change both the frame height and width (but colorspace is okay) and the only 1 input clip is allowed. It can be any build-in filter, avs defined filter or external plugin filter as long as the restrictions are observed.
threads int = 2
number of threads to run. Set this to the number of threads your computer is able to run concurrently.
overlap int = 0
number of pixel to add at the top and bottom border or left and right border. Increase this if you see artifacts where the frame is split.
splitvertical bool = false
if true the frame are cut vertical(and the filter is allowed to change the height) else it is cut horizontal(and the filter is allowed to change the width).
MT Examples/Samples
- Ordinary blur:
MT("blur(1)",2,2)
- Also user defined function (uses variableblur):
MT("unsharp(2,0.7)",2,2)
function unsharpen(clip c,float variance,float k)
{
blr = binomialBlur(c,vary=variance,varc=2,Y=3,U=2,V=2)
return yv12lutxy(blr,c,"y x - " string(k) " * y ",y=3,u=2,v=2)
}
- This one will not produce the intended result but shows how to use the triple quotes:
MT(""" subtitle("Doh") """,4,0)
- It is possible to use mt with resizers that change both height and width by first changing the height and then the width (or reverse) like this:
mt("spline36resize(100,last.height)")
mt("spline36resize(last.width,200)",splitvertical=true)
should produce same result as
spline36resize(100,200)
[edit] SetMTmode() related
SetMTmode() Syntax:
GetMTMode(bool threads)
threads bool = false
if true GetMTMode returns the number of threads used else the current mode is returned (see below).
SetMTmode(int mode, int threads)
Place this at the first line in the avs file to enable temporal (that is more than one frame is processed at the same time) multithreading. Use it later in the script to change the mode for the filters below it.
mode int (2, default 1-6)
there are 6 modes, numbered from 1 to 6.
- Mode 1 is the fastest but only works with a few filters.
- Mode 2 should work with most filters but uses more memory.
- Mode 3 should work with some of the filters that don't work with mode 2 but it is slower.
- Mode 4 is a combination of mode 2 and 3 and should work with even more filters but is both slower and uses more memory.
- Mode 5 is the slowest (slower than not using SetMTMode) but should work with all filters that don't require linear frameserving (that is the frames come in order: frame 0,1,2,...,last).
- Mode 6 is a modified mode 5 that might be slightly faster.
A more technical explanation is available here: MT_modes_explained
threads int = 0
number of threads to use. Set to 0 to set it to the number of processors available. It is not possible to change the number of threads other than in the first SetMTMode.
see [8] or [9]
Example
SetMTMode(2,0) #enables multihreading using thread = to the number of available processors and mode 2
LoadPlugin("...\fft3dgpu.dll") #Loads fft3dgpu
Import("limitedsharpen.avs")
src=AviSource("test.avi")
SetMTMode(5) #change the mode to 5 for the lines below
src=src.converttoyuy2().fft3dgpu()#fft3dgpu needs mode 5 to function.
SetMTMode(2) #change the mode back to 2
src.LimitedSharpen() #because LimitedSharpen works well with mode 2
Subtitle("Number of threads used: " string(GetMTMode(true))
\ " Current MT Mode: " string(GetMTMode())) #display mode and number of threads in use
[edit] Filters known to be working with MT
[edit] How to TEST
- 50.000 frames for difficult bugs
- In VirtualDubMod or VirtualDub or any AVS editor
- Give durations/Percentage/Fps Avisynth.dll/MT rev Avisynth-Filter(s) rev or date
- Please post tests in the related doom9 forum thread (94996) and/or here in the discussion page
[edit] MT() Mode
All filters/scripts working with with SetMTMode (1) or (2), should be working in MT() mode if the filter uses only 1 input clip and both height and width are not changed.
Reverse is not true.
Speed may vary, test by yourself.
Since rev 0.5, MT() internally calls SetMTMode(5) and restores the old mode afterwards so you don't have to add SetMTMode(5) before MT() and restore the old mode after; see [10].
- TBilateral() [11]
- LimitedSharpen()/LimitedSharpenFaster() [12]; faster than with setmtmode(2) [13]
- FFT3DFilter() [14]
- DeGrainMedian() is faster than in setmtmode(3) see: [15]
- Lanczos4Resize() is faster than in setmtmode(3) see: [16]
[edit] SetMTMode() Mode
Setmtmode(1)
Mode 1 is the fastest but only works with a few filter
- MPEG2Source()
- Trim()
- GreyScale()
- RemoveDirt()
See this doom9 forum post.
Setmtmode(2)
Mode 2 should work with most filters but uses more memory.
- LimitedSharpen()/LimitedSharpenFaster()
- AssumeFPS()
- ConvertToYV12()
- Trim()
- TNLMeans()
See this doom9 forum post
- RemoveGrain() [17]
- FFT3DFilter() since rev1.8 see: [18]
- UnDot()
- VagueDenoiser()
- BlindDeHalo3()
See this doom9 forum post.
- Convolution3D()
- PeachSmoother()
- LeakKernelBob() only with rev 0.6 avisynth 2.5.7.3
Setmtmode(3)
Mode 3 should work with some of the filters that doesn't work with mode 2 but is slower.
- DeGrainMedian() but is faster in MT() mode see this doom9 forum post
Setmtmode(4)
Mode 4 is a combination of mode 2 and 3 and should work with even more filter but is both slower and uses more memory.
Setmtmode(5)
Mode 5 is the slowest (Slower than not using SetMTMode) but should work with all filters that doesn't require linear frameserving (that is the frames come in order: frame 0,1,2,...,last)
- Cedocida codec, see [19] or try Setmtmode(6)
Setmtmode(6)
Mode 6 is a modified mode 5 that might be slightly faster (But still slower than not using SetMTMode).
[edit] Filters known not to be working with MT
[edit] Known problems Requests Others
[edit] Known problems
- AVI Import Filter error: (Unknown) (80040154) - solution: A missing dll might be the problem: msvcr71.dll msvcp71.dll should be in the windows\sytem32 directory or windows\SysWOW64 (Windows 7 64Bit)
- FIXED -
- Was affecting Xvid encoder speed (Xvid rev 1.0x only) performance (in 2005):
- SPEED
- To customize AVS scripts in DVD Rebuilder, use RP-OPT, see [25] and [26]
- For the simple quote problem, use triple quote: instead of MT("ffdshow("default")") use MT(""" ffdshow("default") """) see [27]
- For the Writefile() with SetMTMode() problem, use last 0.6 and avisynth 2.5.7.3 rev [28]
- Workaround for spline36resize() see [29]
- Masktools > v2.0a18



