GenMotion - Generate Motion for Global Compensation
ะก-plugin for Avisynth 2.5

Version 0.7 April 8, 2004
Copyright (C)2003-2004 Alexander G. Balakhnin aka Fizick.
http://bag.hotmail.ru

This plugin generates a motion for global motion compensation,
using ready-made motion estimation data.
As a such data, the filter uses a log file of Deshaker VirtualDub plugin (by Gunnar Thalin).
The GenMotion plugin may be used for:
- global motion compensation for strong temporal denoising and clip (film) restoration.
- simple partial motion stabilization (not as good as Deshaker);

- recreating of damaged frames by motion interpolation,

- creating series of intermediate frames for frequency (fps) changing.

Video processing:

1. Preparation of motion estimation data:
In VirtualDub, run only first pass with Deshaker plugin, and remember the filename of Deshaker.log file.
You must set Deshaker parameters according to its documentation.
During Pass 1 the Deshaker plugin tries to find the panning, rotation and zoom that,
when applied to the current image, makes it look like the previous image (almost).
2. Motion compensation:
Use GenMotion plugin in Avisynth script line such as:
Genmotion(clip,filename="e:\deshaker.log", delta=1,tff=true, subpixel=1, pixaspect=1.0)

Plugin Parameters:

filename - name of Deshaker log file
delta - used timestep (in frame units), from -1.0 to 1.0, in particular:
      delta= -1.0 is full backward motion compensation, (last frame will stay unchanged)
      delta=1.0 is full forward motion compensation, (frame 0 will stay unchanged)
      delta=-0.5 is simple backward semi-stabilization, (last frame will stay unchanged)
      delta=0.5 is simple forward semi-stabilization, (frame 0 will stay unchanged)
      delta=0 is null transform.
tff - fields order for interlaced video (true or false, default = as Avisynth assumes):
      set as true for top field first (most analog video),
      set as false for bottom field first (DV source)
subpixel - mode of subpixel accuracy and interpolation (0 to 2, default=2):
    0 - pixel accuracy (at nearest pixel), no interpolation (fast),
    1 - subpixel accuracy with bilinear interpolation (best for noisy movie),
    2 - subpixel accuracy with bicubic interpolation (best for clean movie).
pixaspect - pixel aspect (1.0 for 768x576,  default=1.0)

grey - convert to grey tone (true or false, default=false):
    set as true to convert to grey tones with fast processing,
    set as false to preserve colors.
dxmax - maximum value of x shift in motion data, (default = 100),
dymax - maximum value of y shift in motion data, (default = 50),
rotmax - maximum value of rotation (degree) in motion data, (default = 5),
zoommax - maximum value of zoom in motion data, (default = 1.2),
    (if any above max parameter is positive, the motion data value will be limited to it,
    if negative, the motion data value will be reseted to null )



Using plugin for simple partial motion stabilization (deshaking)

Use GenMotion plugin in Avisynth script with line such as:
Genmotion(clip,filename="e:\deshaker.log", delta=0.5)
You will get clip with half values of shakes.

Using plugin for preparation motion compensated clips with following strong temporal denoising.

1. Load original (input) clip (I),
2. Make clip (F) with full forward motion compensation,
3. Make clip (B) with full backward motion compensation,
4. Make a interleave clip, with compensated frames before and after every original frame;
We will get a long clip (with triple length), with every 3 successive frames corresponded to same time.
5. Apply some temporal filter that uses pixel differences between previous, current and next frames,
for example conditional temporal median filter.
6. Select every third (original non-compensated but filtered) frame to output.
The filtered clip will not have a lot of artifacts, produced by general motion
(camera's shake, pan, zoom will be compensated.)

Needed software


1. The program is plugin (filter) for free  Avisynth 2.5  (http://www.avisynth.org)

    Tested with versions 2.52 and 2.53.

    Version 2.54 also may be used, see note below.

2. Filter is needed in free Avisynth C Interface (avithynth_c.dll) by Kevin Atkinson.

   Copyright (C) 2003 Kevin Atkinson )

   

   Tested with versions 0.14, 0.15, which use CDECL function call type.

    Notes.

    -   The Avisynth v.2.53  has internal Avisynth_C plugins support  v.0.14,

    external avisynth.dll is not needed for plugin loading.

    -. Latest experimental Avisynth C Interface v.0.20 use STDCALL call type,

     which have some bug and is NOT compatible with current version of GenMotion.

     - The Avisynth v.2.54  has internal Avisynth_C plugins support  v.0.20,

    with declared support both CDECL and STDCALL type, but have problem with it.

    - The internal support of Avisynth C removed in new Avisynth v.2.55 alpha.

    - The external avisynth.dll work well with all these versions.

    - We hope these problem will be solved


3. Virtual Dub videoeditor by Avery Lee (http://www.virtualdub.org)

   Tested with version 1.4.13

4. Deshaker Plugin (for VirtualDub) by Gunnar Thalin

   Tested with version 1.4

5. The program compiled with free GCC 3.3.1, MinGW, MSYS (all not required for using binary Genmotion.dll)


Some (tested) suitable temporal filters


CTMedian (Conditional Temporal Median) by Kevin Atkinson

  and its new version renamed to DeSpot by me
STMedianFilter by Tom Barry - [email protected]
FluxSmooth by Ross Thomas <>

RemoveDirt by Rainer Wittmann [email protected]
Please, make a tests to add filters to the list!
For proposed method of denoising with the GenMotion,
such temporal filter must compare pixel with previous and next frame,
and make some smoothing only if difference between previous and next frame is small.
These filters also may make additional internal (small) local motion compensation.

Sample script:


Avisource("input.avi")
loadplugin("avisynth_c.dll")
loadCplugin("genmotion.dll")
i=converttoYV12()
f=GenMotion(i,filename="e:\deshaker.log",delta=1)
b=GenMotion(i,filename="e:\deshaker.log",delta=-1)
interleave(f,i,b)
loadCplugin("DeSpot.dll")
DeSpot(p1=40,p2=14,pwidth=30,pheight=30,mthres=22,mwidth=4,mheight=4,interlaced=false)
selectevery(3,1)
converttoYUY2()

By the way, then you may load this AVS file in VirtualDub,
and run second pass of Deshaker for image stabilization (and coding) of filtered clip.

Acknowledgments

Thanks to Gunnar Thalin for detailed info about Deshaker log file format

and very useful discussions.
Thanks to Kevin Atkinson for his Avisynth C plugin.

Deshaker log file format

During Pass 1 the Deshaker plugin tries to find the panning, rotation and zoom that,
when applied to the current image, makes it look like the previous image (almost).
The values on each line in the file are (from left to right):
frame number (or fields number), x- and y-panning (in pixels), rotation (in degrees) and zoom factor.
You can edit the log file manually (but use fixed line format).
You can delete lines that got completely wrong (and that you don't care to try to fix in a better way).
Gaps in the frames numbers are treated as zero-panning, zero rotation and no scaling.
If a frame exists more than once in the log file, the last line is used.

Version changes:

version 0.1, 30 November 2003 - initial (not public)
version 0.2, 7 December 2003 - add interlaced support (not public)
version 0.3, 13 December 2003 - add subpixel accuracy, pixel aspect (first public version)

version 0.4, 14 December 2003 - add deflick for luma correction
version 0.5, 28 December 2003 - corrected formula for delta<0 (thanks to Gunnar Thalin), some bugs fixed

version 0.6, 05 April 2004 - add bicubic interpolation (set as default),  add grey parameter, remove deflick,
                                                correct first and last frame calculation, some reorganization, some speed optimization,
                                                use Avisynth C version 0.15, released with source under GNU GPL 2
version 0.7, 08 April 2004 - add limit parameters dxmax, dymax, rotmax, zoommax
 


Current version limitations:

The plugin works only in YV12.
Not optimized, slow.
 

License


This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Please consider to make some donation to be registered user.


Download GenMotion version 0.7

 

(Avisynth C Interface DLL v.0.15 is included)

Return to main page