MVTools

From Avisynth wiki
Jump to: navigation, search
Abstract
Author Manao, Fizick, Tsp, TSchniede, SEt, cretindesalpes, pinterf
Version v2.5.11.22 / v2.7.15.22
Download mvtools-v2.5.11.22.zip

mvtools-2.7.15.22-pfmod.7z (8-16-bits, 420,422,444 support, x86/x64)

Category Support filters, Deep color tools
Requirements
  • AviSynth 2.6.0 or greater
  • Avisynth+ r2294 or greater for native 10+ bits
  • YV12
  • YUY2
  • YV16, YV24 (2.7.1-)
  • YUV 4:2:0, 4:2:2, 4:4:4 10-16 bits
License GPLv2
Discussion Doom9, continued

Doom9 v2.6 mod, v2.7mod

Contents

About MVTools

MVTools plugin for AviSynth 2.6 is a collection of functions for estimation and compensation of objects motion in video clips. Motion compensation may be used for strong temporal denoising, advanced framerate conversions, image restoration and other tasks.

The plugin contains the motion estimation server-function MAnalyse to find the motion vectors and several motion compensation client-functions (MCompensate, MMask and others) which use these vectors.

Plugin uses block-matching method of motion estimation (similar methods are used in MPEG2, MPEG4, etc). At analysis stage plugin divides frames by small blocks and try to find for every block in current frame the most similar (matching) block in second frame (previous or next). The relative shift of these blocks is motion vector. The main measure of block similarity is sum of absolute differences (SAD) of all pixels of these two blocks compared. SAD is a value which says how good the motion estimation was.

The output of MAnalyse (server) is special clip with motion vector information in some format.

At compensation stage the plugin client functions read the motion vectors and use them to move blocks and form motion compensated frame (or realize some other full or partial motion compensation or interpolation function). Every object (block) in this (fully) compensated frame is placed in the same position as this object in current frame. So, we may (for example) use strong temporal denoising even for quite fast moving objects without producing annoying artifacts and ghosting (object's features and edges are coincide if compensation is perfect). Plugin can create compensated neighbor frames for every current frame, and denoise it by internal function. Alternatively, you can use compensated and original frames to create interleaved clip, denoise it by any external temporal filter, and select central cleaned original frames for output (see examples).

Of course, the motion estimation and compensation is not ideal and precise. In some complex cases (video with fading, ultra-fast motion, or periodic structures) the motion estimation may be completely wrong, and compensated frame will be blocky and (or) ugly. Severe difficulty is also due to objects mutual screening (occlusion) or reverse opening. Complex Avisynth scripts with many motion compensation functions may eat huge amount of memory and result in very slow processing. It is not simple but quite advanced plugin. Use it for appropriate cases only, and try to tune its parameters. There are many discussions about motion compensation using at doom9 Avisynth forum. In particular see old MVTools thread, true motion thread, new MVTools thread and some other. Try to read the postings in addition to this documentation and ask for support there. If you really interested in motion estimation and compensation topics, you can easy find numerous scientific publications (use WWW search).

Notes 1: The plugin is still under development. Version 2.5.11.22 version has some limitations. Only progressive YV12, YUY2 video is supported. Use color format conversion and try use (smart) bob-deinterlace for interlaced video (SeparateFields may works too with or without SelectEven/SelectOdd). Some complex scripts (MVBOB, MCBOB, TempGaussMC) use MVTools for motion compensated deinterlace. Alternatively you can try to use Motion plugin by mg262.

Notes 2: The pfmod branch (2.7.x.x.) supports YV16 and YV24 colorspaces under AviSynth 2.6 and AviSynth+ versions. Stacked 16 bit output for MDegrain1-6 and MDegrainN are also supported in general. Native 10-16 bit colorspaces are available when using MVTools with AviSynth+ r2294-


Official documentation: http://www.avisynth.nl/users/fizick/mvtools/mvtools2.html

Common parameters

Filters that use motion vectors have common parameters. Those are the scene-change detection thresholds, and the isse mmx flag. They also use one or several vectors stream, which are produced by MAnalyse.

  • thSCD1 (int): threshold which decides whether a block has changed between the previous frame and the current one. When a block has changed, it means that motion estimation for it isn't relevant. It occurs for example at scene changes. So it is one of the thresholds used to tweak the scene changes detection engine. Raising it will lower the number of blocks detected as changed. It may be useful for noisy or flickered video. The threshold is compared to the SAD (Sum of Absolute Differences, a value which says how bad the motion estimation was ) value. For exactly identical blocks we have SAD=0. But real blocks are always different because of objects complex movement (zoom, rotation, deformation), discrete pixels sampling, and noise. Suppose we have two compared 8x8 blocks with every pixel different by 5. It this case SAD will be 8x8x5 = 320 (block will not detected as changed for thSCD1=400). If you use 4x4 blocks, SAD will be 320/4. If you use 16x16 blocks, SAD will be 320*4. Really this parameter is scaled internally in MVTools, and you must always use reduced to block size 8x8 value. Default is 400 (since v.1.4.1).
  • thSCD2 (int): threshold which sets how many blocks have to change for the frame to be considered as a scene change. It is ranged from 0 to 255, 0 meaning 0 %, 255 meaning 100 %. Default is 130 ( which means 51 % ).
  • isse (int): flag which allows to enable (if set to True) or disable (if set to False) ISSE, MMX and other CPU optimizations (for debugging). Default is True. If your processor doesn't support CPU optimizations, it will be disabled anyway ( and you won't be able to activate them ).
  • planar (bool): flag to use special planar color format for YUY2 clips both for input and output of function. It uses special trick for storing of frames with planar color data organization (separate Y, U, V planes in memory) in normal interleaved YUY2 frames format as a container. This way we can avoid numerous internal interleaved to planar conversions and increase speed. You can convert normal interleaved YUY2 source clip to planar format with Interleaved2planar function from RemoveGrain plugin by kassandro, and convert final result by Planar2interleaved function. This special planar YUY2 format is also supported by Removegrain plugin by Kassandro, MaskTools2 plugin by Manao and some others. This trick will not be needed in Avisynth v2.6 with native support of planar YV16 format. This parameter is ignored for YV12 clips. Note: super clip is always planar. Default is planar=false.


Filters

Filter Description Color format
MSuper

Get source clip and prepare special "super" clip with multilevel (hierarchical scaled) frames data.

YV12, YUY2
MAnalyse

Get prepared multilevel super clip, estimate motion by block-matching method and produce special output clip with motion vectors data.

YV12, YUY2
MCompensate

Do a full motion compensation of the frame.

YV12, YUY2
MMask

Creates a mask clip from source clip with motion vectors data.

YV12, YUY2
MSCDetection

Creates scene detection mask clip from motion vectors data.

YV12, YUY2
MShow

Shows the motion vectors on padded source by super clip opening.

YV12, YUY2
MDepan

Get the motion vectors, estimate global motion and put data to output frame in special format for DePan plugin.

YV12, YUY2
MFlow

Do a motion compensation of the frame not by blocks (like MCompensate), but by pixels.

YV12, YUY2
MFlowInter

Motion interpolation function.

YV12, YUY2
MFlowFps

Will change the frame rate (fps) of the clip. The function can be used for frame rate conversion, slow-motion effect, etc.

YV12, YUY2
MBlockFps

The function uses block-based partial motion compensation to change the framerate (fps) of the clip.

YV12, YUY2
MFlowBlur

Experimental simple motion blur function. It may be used for FILM-effect (to simulate finite shutter time)..

YV12, YUY2
MDegrain1

Temporal denoising with motion compensation. MDeGrain1 has a temporal radius of 1.
(16-bit support in version 2.6.0.5)

YV12, YUY2
MDegrain2

Temporal denoising with motion compensation. MDeGrain2 has a temporal radius of 2.
(16-bit support in version 2.6.0.5)

YV12, YUY2
MDegrain3

Temporal denoising with motion compensation. MDeGrain3 has a temporal radius of 3.
(16-bit support in version 2.6.0.5)

YV12, YUY2
MDegrainN

Temporal denoising with motion compensation. MDeGrainN has a temporal radius given by the tr parameter, and uses a special motion vector clip.
(16-bit support in version 2.6.0.5)

YV12, YUY2
MRecalculate

Refines and recalculates motion data of previously estimated motion vectors.

YV12, YUY2
MVShow

Shows the motion vectors.

YV12, YUY2


Changelog

Version Date Author Changes
2.7.15.22 2017.03.16 pinterf Fix: 16 bit SAD for non-AVX code path

Misc: MDegrain1-6: add error on lsb_flag=true for non-8 bit sources

2.7.14.22 2017.02.06 pinterf Fix: MAnalyze divide=2 showed "vector clip is too small" (inherited from 2.6.0.5, sanity check was done but length was not filled for divideextra data)

Fix: MFlow access violation in internal mv resizer when resizing factor was big (MCaWarpSharp3 4x supersampling case) (bug possibly introduced in upstream 2.5.11.22)

2.7.13.22 2017.02.01 pinterf Fix: MDegrain1-6,N 10-16 bit thSCD scaling

Fix: MVShow: tolerance scaling for 10-16 bits

2.7.12.22 2017.01.20 pinterf New: Faster SATD (dct=5..10) 8 bit: updated x264 function selectors, SSE2/4/AVX/AVX2; +10% speed for a whole typical MDegrain3 process on i7-3770

New: Much Faster SATD (dct=5..10) 10-16 bit: SSE2/SSE4 instead of C +50% speed for a whole typical MDegrain3 process (which is approx half speed of 8 bit)

2.7.11.22 2017.01.16 pinterf New: MDegrain6

Mod: MDegrain1-6 SSE4 for 10-16 bit (was: C. 3-5% gain, wasn't bottleneck)

2.7.10.22 2016.12.28 pinterf Fix: for YV12 the debug info text chroma part was positioned at wrong place
2.7.9.22 2016.12.20 pinterf Apply 2.5.11.9-svp analysis speedup, mainly when chroma is involved
2.7.8.22 2016.12.18 pinterf Fix: YUY2 input access violation (regression after 2.7.0.22d) - Fixed also in Depan.dll

Fix: MDegrain: free up YUY2 planes only if not planar input (bug inherited from 2.5.11.22 MDegrain3) resulting in freeze at script exit

2.7.7.22 2016.12.14 pinterf Optimizing 8 bits

speed: change some 8 bit SAD functions for the better
speed: separating bottleneck 8 bit/16 bit code paths in order not to use slower int64 calculations for 8 bit, where there are no integer overflow problems
speed: more __forceinlines for helping the compiler
info: general speed gain of 5-15% compared to 2.7.6.22, much reduced speed gap compared to the "classic" YV12 8 bit mvtools2 versions

2.7.6.22 2016.12.04 pinterf fix: sumLumaChange underflow (used for dct=2,6,9) (regression during 16 bit support)

fix: MeanLumaChange scale for 10-16 bits (used for dct=2,6,9)
fix: Mask fix: 8 bit mask resizer bug in SIMD intrinsics (regression on inline asm -> SIMD transition)
Fix: dctmode=1,2: pixel distance was not corrected for 16 bit pixel sizes
speed: Let's help VS2015 with some __forceinline directives to recognize the truth.
speed: Misc optimizations throughout the code (bit shifts instead of div or mul)
speed: FFTW DCT: C code replaced with SIMD SSE2/SSE4 (FloatToBytes, BytesToFloat)
speed: 16 bit SAD: a few optimizations in SSE2, AVX-coded SSE2 and AVX2 codepath
VS2015 compiler: /MT -> /MD (from static to dynamic dlls - now it reallys need VS2015 redistributables)

2.7.5.22 2016.11.19 pinterf Milestone release:

General support of 10-16 bit formats with Avisynth Plus (r2294 or newer recommended) with new MDegrain4 and MDegrain5 filters.
Fix for MSCDetection: scene change filler pixel default value was always 0 (2.7.1.22 regression)
MCompensate: possible bugfix bottom padding UV
Fix SAD for 10-16 bit depths for horizontal block sizes >= 16
Fix nSCD2 (Scene change threshold block count %) (2.7.1.22 regression)
MBlockFPS: overlap fixes (right columns and bottom lines)
MBlockFPS: overlap fix: missing copy buffer to output

2.7.1.22 2016.10.20 pinterf YV16 and YV24 avaliable

dct modes >= 5 now use SATD again (so far it was in dead code, contrary to 2.5.13.1 remarks)
New: MDegrain4, MDegrain5
Experimental native 10-16 bit support (MSuper, MAnalyze, MDegrain1-5, MDegrainN) including 16 bit SATD (slow C) and SSE2 optimized regular SAD for 8+ (for 10+ bits you need at least Avisynth+ r2290)
Inline assembly rewritten to intrinsics -> 64 bit build is possible in VS2015 (External assembly untouched)

2.7.0.22 2016.04.29 pinterf Integrate Fizick's upstream changes of 2.5.11.22
2.7.0.1 2016.03.31 pinterf MVTools-pfmod

2.6.0.5 x64 capable version ported under AviSynth 2.6 API
Fixed access violation in MDepan
Fixed access violation in x64 asm code
Built with Visual Studio 2015 Community Edition, v140_xp toolset
Compiler: Intel C++ 16 (because of inline 64 bit asm code)
See discussion and GitHub page for more information.

2.6.0.5 2012.07.17 Firesledge MCompensate, MDegrainN: fixed a bug causing occasionally horizontal magenta stripes in multithreading mode.
2.6.0.4 2012.06.14 Firesledge MCompensate: fixed artifacts related to overlap with tr > 3 in multithreading mode.
2.6.0.3 2012.05.13 Firesledge MDegrainN: fixed artifacts related to overlap with tr > 3 in multithreading mode.
2.6.0.2 2012.05.01 Firesledge MAnalyse: fixed a threading issue when using FFTW.
2.6.0.1 2012.03.12 Firesledge

MAnalyse: fixed potential crash in multithreading mode.
MDegrainN: fixed systematic crash in multithreading mode.
All MDegrain functions: fixed potential crash when thSAD is set to 0.

2.6.0.0 2012.03.11 Firesledge

MDegrainN: internally uses MDegrain1/2/3 when tr ≤ 3, for optimal speed.
MCompensate: added multi-compensation mode for easy use with temporal filters.
MAnalyse, MSuper, MCompensate, MDegrainN: added multithreading (but partially, not for all code paths) using AVSTP.
MAnalyse: fixed a corruption of the global motion vector.
Improved page setting for this documentation.

2.5.14.2 2012.01.10 Firesledge Fixed MScaleVect with multi-vector clips.
2.5.14.1 2011.12.13 Firesledge Fixed crashes in the MDegrain functions when using both planar=true and lsb=true.
2.5.14.0 2011.11.28 Firesledge and Vit Added MStoreVect, MRestoreVect and MScaleVect from the Vit's MVExtras plugin.
2.5.13.1 2011.11.09 Firesledge

MAnalyse, MRecalculate: added an SATD approximation for blksize > 16 and dct ≥ 5. Previously, the SATD calculation was silently bypassed and always returned a null SAD value.
Functions now check that the pel setting is the same in the superclip and the motion vectors, instead of crashing if not.

2.5.13.0 beta 2011.09.11 Firesledge

MRecalculate: Can now process multi-vector clips.
All functions: Added the -Vit-'s fix that could improve the multithreading stability.

2.5.12.1 beta 2011.09.10 Firesledge MAnalyse: Fixed the ghosting bug introduced in the previous version.
2.5.12.0 beta 2011.09.10 Firesledge

MDegrainN added.
MAnalyse: Added the "multi" mode for MDegrainN.
MAnalyse: Documented the negative delta values and fixed some functions accordingly.
MFlowInter: Fixed the YUY2 planar mode.

2.5.11.2 beta mod16b 2011.05.11 Firesledge Fixed a regression in MDegrain1/2/3, related to the mod16 versions. thSADC is now taken into account correctly (instead of using thSAD).
2.5.11.2 beta mod16a 2011.04.10 Firesledge Merged 2.5.11.2 and 2.5.11 mod16a versions.

Changelog up to v2.5.11.22


External Links


Personal tools