Section4 Importing filters from VirtualDub のバックアップソース(No.3)

#contents

***Q4.1: VirtualDubのフィルタをインポートするスクリプトの最新版は、どこでダウンロードすることができますか? [#m473f7e5]

A: AviSyntスクリプトは、[[ShareFunctions:http://www.avisynth.org/ShareFunctions]]ページにあります。もしくは、vdub_filtersv15.zipというパッケージを[[[1]:http://forum.doom9.org/showthread.php?s=&threadid=23804]]か[[[2]:http://neuron2.net/hosted.html]]から、ダウンロードすることもできます。 

***Q4.2: どのフィルタがインポートされますか? [#vfe656f8]

A: ほとんどのフィルタが。関連するキュメントを読んでください。

***Q4.3: これらのスクリプトは、RGB空間やYUV空間で動作しますか? [#bc2767d8]

A: RGB空間(RGB32)のみです。

***Q4.4: そのようなスクリプトは、どうやって作るのですか? [#g0a12952]

A: スクリプト例(このVirtualDubフィルタは、[[[Donalds homepage]:http://neuron2.net/]]から、ダウンロードすることが出来ます):

Smart Bob by Donald Graft:

 function VD_SmartBob(clip ''clip'', bool ''show_motion'', int ''threshold'', bool ''motion_map_denoising'')
 LoadVirtualdubPlugin("d:\bob.vdf", "_VD_SmartBob", 1)
 return clip.SeparateFields._VD_SmartBob(clip.GetParity?1:0,
 \  default(show_motion,false)?1:0, default(threshold,10),
 \  default(motion_map_denoising,true)?1:0)
 }

The VirtualDub plugin is imported with the command "LoadVirtualdubPlugin". The first argument gives the path of the plugin, the second argument the name for the plugin that will be used in the script and the third argument is called the preroll.

The preroll should be set to at least the number of frames the filter needs to pre-process to fill its buffers and/or updates its internal variables. This last argument is used in some filters like: SmartBob?, SmartDeinterlace?, TemporalCleaner? and others. The reason is that due to filtering architecture of Virtual Dub the future frames can't be accessed by a filter. Dividee reports: "In the "Add filter" dialog of VirtualDub, some filters have a "Lag:" value in their description. I think this is the value that must be used as preroll. Unfortunately, this indication is not always present. In those cases you have to guess." Of course you can always ask the creator of the filter.

The first step is to find out the sequence of the arguments in the last line where the clip is returned. Configure the script in VirtualDub and select "Save processing Settings" in the File Menu or press Ctrl+S. Open the created .vcf file with a text editor and you should see lines like this:

VirtualDub.video.filters.Add("smart bob (1.1 beta 2)");

VirtualDub.video.filters.instance[0].Config(1, 0, 10, 1);

The order of the arguments is the one that has to be used in AviSynth. To find the role of the arguments, play with them in VirtualDub and examine the resulting lines.

The second step is to test the filter and to compare it with the VirtualDub filter itself. For the programming itself you can learn a lot by looking at the script which are already contained in vdub_filters.avs.

Example script which uses the function VD_SmartBob:

 Import("d:\vdub_filters.avs")
 AviSource("d:\filename.avi")
 ConvertToRGB32()  # only when necessary (but doesn't hurt)
 VD_SmartBob(false, 10, true)
 ConvertBackToYUY2()  # only when necessary