Plugins

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(some reformatting)
(LoadVirtualDubPlugin: Update for avs+, document rangehint)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Commands for Loading Plugins ==
+
<div style="max-width:62em" >
With these functions you can add external filters to AviSynth.
+
With these functions you can add external filters (DLLs) to the AviSynth script environment.
 +
__TOC__
  
 +
====LoadPlugin====
 +
Loads one or more [[Filter_SDK|standard (C++)]] AviSynth plugins.
  
===LoadPlugin===
+
{{FuncDef
Loads one or more external AviSynth plugins (DLLs).
+
|LoadPlugin(string ''filename'' [, string ''filename''...])
 +
}}
 +
:{{Par2|filename|string|}}
 +
::The path of the '''.DLL''' file(s).  
  
LoadPlugin ("filename" [, ...])
 
  
===LoadCPlugin===
+
====LoadCPlugin====
Loads so called AviSynth C-plugins (DLLs). C-plugins are created on pure C language and use special "AviSynth C API" (unlike ordinary Avisynth plugins which are created with MS C++). C-plugins must be loaded with LoadCPlugin() or Load_Stdcall_Plugin(). Please note that Load_Stdcall_Plugin() is an alias for LoadCPlugin().  
+
Loads so-called AviSynth ''C-plugins''. C-plugins are created in pure [[wikipedia:C_(programming_language)|'''C''']] (unlike most Avisynth plugins, which are created with [[wikipedia:Visual_C%2B%2B|MS C++]]), use a special [[Filter_SDK/C_API|'''C API''']], and must be loaded with '''LoadCPlugin'''.  
  
LoadCPlugin ("filename" [, ...])
+
{{Func4Def
Load_Stdcall_Plugin ("filename" [, ...])
+
|LoadCPlugin(string ''filename'')
 +
|LoadCPlugin(string ''filename'' [, string ''filename''...]) {{AvsPluscon}}
 +
|Load_Stdcall_Plugin(string ''filename'')
 +
|Load_Stdcall_Plugin(string ''filename'' [, string ''filename''...]) {{AvsPluscon}}
 +
}}
 +
:{{Par2|filename|string|}}
 +
::The path of the '''.DLL''' file(s).
 +
*The plugin's documentation should advise you if '''LoadCPlugin''' is needed.
 +
*'''Load_Stdcall_Plugin''' is merely an ''alias'' or alternate name.
 +
*Advice: keep these plugins outside your [[#Plugin Autoload and Name Precedence|autoload directory]] to prevent crashes.
  
Kevin provides a LoadCPlugin.dll that overloads the LoadCPlugin() verb to support plugins compiled using the C subroutine calling sequence, use Load_Stdcall_Plugin() to load stdcall calling sequence plugins when using Kevins version. Advice: keep these plugins outside your auto plugin loading directory to prevent crashes. ([http://forum.doom9.org/showthread.php?s=&threadid=58840 Doom9 discussion]), ([http://kevin.atkinson.dhs.org/avisynth_c/ AVISynth C API by Kevin A.)]
 
  
===LoadVirtualDubPlugin ===
+
====LoadVirtualDubPlugin ====
 +
Loads a plugin written for [[VirtualDub]]. These are distributed as special DLLs with the file extension '''.VDF'''.
  
This loads a plugin written for [[VirtualDub]]. "filename" is the name of the .vdf file. After calling this function, the filter will be known as "filtername" in AviSynth. VirtualDub filters only supports [[RGB32]]. If the video happens to be in RGB24-format, then you must use [[ConvertToRGB32]] ([[ConvertToRGB]] won't suffice).
+
{{FuncDef
 +
|LoadVirtualDubPlugin (string ''filename'', string ''filtername'' [, int ''preroll''])
 +
}}
  
LoadVirtualDubPlugin ("filename", "filtername", preroll)
+
:{{Par2|filename|string|}}
 +
::The path of the '''.VDF''' file.
 +
:{{Par2|filtername|string|}}
 +
::The name to be given to the plugin function after loading in AviSynth.
 +
:{{Par2|preroll|int|0}}
 +
::Some filters' output depends on previous frames; for these, {{FuncArg|preroll}} should be set to a suitable number.
  
Some filters output depends on previous frames; for those 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.
+
Note that there is a new parameter but _not_ for use in LoadVirtualdubPlugin, but when calling the loaded VDF filter from the script.
 +
:{{AvsPluscon}}{{Par2|rangehint|string|""}}
 +
:This extra filter parameter added at the end of filter's (unnamed) parameter list: <code>string ''rangehint''</code>.
 +
:The imported Virtualdub filters (of course which are supporting the extra feature) are getting and extra named parameter to the end.
 +
:This parameter can tell the filter about a YUV-type clip colorspace info
 +
:Allowed values:
 +
::* "rec601": limited range + 601
 +
::* "rec709": limited range + 709
 +
::* "PC.601": full range + 601
 +
::* "PC.709": full range + 709
 +
::* ""      : not defined (same as not given)
 +
:Parameter will be ignored when clip is non-YUV
 +
:How it works: the hint will _not_ change the internal VirtualDub colorspace constant (e.g. kPixFormat_YUV420_Planar -> kPixFormat_YUV420_Planar_709 will not happen).
 +
:Instead the base color space is kept and colorSpaceMode and colorRangeMode will set in PixmapLayout.formatEx.
 +
:Filter can either use this information or not, depending on supported API version and its implementation.
 +
:E.g. <code>Crossfade(20,30) -> Crossfade(20,30,"rec601")</code> (a bit stupid example, just for showing the syntax because this specific filter won't use it).
  
===LoadVFAPIPlugin===
+
*Supported color spaces and features:
This allows you to use VFAPI plugins (TMPGEnc import plugins).
+
:*VirtualDub filters originally support only [[RGB32]].
 +
:*{{AvsPluscon}} Since Avisynth+ r2724 LoadVirtualdubPlugin was updated to support newer interface versions.
 +
:This update changed the supported interface version from V6 to V20, and Filtermod version 6 (partial support)
 +
:Supported extras:
 +
:VirtualDub2 support with extended colorspaces
 +
::* Allow RGB24, RGB48, RGB64 besides RGB32
 +
::* RGBP/RGBAP 8 bit: since this format is not supported directly by Virtualdub filters, LoadVirtualdubPlugin automatically converts 8 bit Planar RGB to/from RGB24, RGBAP to/from RGB32 (lossless)
 +
::* RGB48/RGBP16/RGBAP16: since this format is not supported directly by Virtualdub filters, LoadVirtualdubPlugin automatically converts them to/from RGB64 (lossless)
 +
::* YUV(A) 8 bits: YV12, YV16, YV24, YV411, YUVA420P8, YUVA422P8, YUVA444P8
 +
::* YUV(A) 10-16 bits (properly set "ref_x" maximum levels, no autoconvert)
 +
:*Supports prefetchProc2 callback (API >= V14 and prefetchProc2 is defined) for multiple input frames from one input clip
 +
:*PrefetchFrameDirect and PrefetchFrame are supported. PrefetchFrameSymbolic not supported
 +
:*Supports prefetchProc callback (API >= V12 and prefetchProc is defined)
 +
:*Supports when filter changes frame count of the output clip
 +
:*Supports specifying some colorspace properties. See ''rangehint''
  
LoadVFAPIPlugin ("filename", "filtername")
+
*Usage example ([http://trevlac.us/colorCorrection/ ColorTools]) &ndash; see [http://forum.doom9.org/showthread.php?t=72634 '''here'''] (doom9).
 +
*See [[FAQ_using_virtualdub_plugins|FAQ using Virtualdub plugins]] for more information.
  
 +
====LoadVFAPIPlugin====
 +
Loads [[Vfapi|VFAPI]] plugins (''eg'', [[Importing_media#How_do_I_load_my_video_clip_into_AviSynth.3F|QTReader]], [[TMPGEnc]]). These are distributed as special DLLs with the file extension '''.VFP'''.
  
 +
{{FuncDef
 +
|LoadVFAPIPlugin (string ''filename'', string ''filtername'')
 +
}}
 +
:{{Par2|filename|string|}}
 +
::The path of the '''.VFP''' file.
 +
:{{Par2|filtername|string|}}
 +
::The name to be given to the plugin function after loading in AviSynth.
 +
</div>
  
== Plugin Autoload and Name Precedence v2 ==
 
  
It is possible to put all plugins and script files with [[User_defined_script_functions|user-defined functions]] or (global) [[Script_variables|variables]] in a directory from where all files with the extension .AVSI (v2.08, v2.5, the type was .AVS in v2.05-2.07) and .DLL are loaded at startup, unloaded and then loaded dynamically as the script needs them.
+
==== Plugin Autoload and Name Precedence ====
 +
<div style="max-width:62em" >
 +
It is possible to put all plugins and script files with [[User_defined_script_functions|user-defined functions]] or (global) [[Script_variables|variables]] in an ''autoload directory'', from which all files with the extension '''.AVSI''' and '''.DLL''' are loaded [[The_script_execution_model/Sequence_of_events|at startup]], then unloaded and reloaded dynamically as the script needs them.
  
.AVSI scripts in this directory should only contain function definitions and global variables, no main processing section (else strange errors may occur), it also is not recommended to put other files in that directory.
+
'''.AVSI''' scripts in this directory should only contain function definitions and global variables; they should not have a main processing section (else strange errors may occur). It also is not recommended to put other files in that directory.
  
The directory is stored in the registry (the registry key has changed for v2.5). You can use double-clicking a .REG-file with the following lines to set the path (of course inserting your actual path):
+
The directory is stored in the registry. You can use double-clicking a .REG-file with the following lines to set the path (of course inserting your actual path):
+
<div {{BoxWidthIndent|38|1}} >
 
  REGEDIT4
 
  REGEDIT4
 
   
 
   
 
  [HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth]
 
  [HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth]
 
  "plugindir2_5"="c:\\program files\\avisynth 2.5\\plugins"
 
  "plugindir2_5"="c:\\program files\\avisynth 2.5\\plugins"
 
+
</div>
 
The order in which function names take precedence is as follows:
 
The order in which function names take precedence is as follows:
  
# user-defined function (always have the highest priority)
+
# User-defined function (always have the highest priority)
# plugin-function (higher priority than built-in, will override a built-in function)
+
# Plugin (external) function (higher priority than built-in)
# built-in function
+
# Built-in (internal) function
  
Inside those groups the function loaded at last takes precedence; there is no error in a namespace conflict.
+
Inside those groups the function loaded ''last'' takes precedence; there is no error in a namespace conflict.<br>
 +
It follows that there is no harm in loading the same plugin more than once.{{Dubious|Talk:Plugins#Loading_same_plugin_more_than_once}}
 +
</div>
  
  
== Plugin Autoload and Conflicting Function Names v2.55 ==
+
==== Plugin Autoload and Conflicting Function Names ====
 +
<div style="max-width:62em" >
 +
A problem that may arise when multiple plugins have functions with the same name. You won't know which function will be called in your script, as this will depend on loading order. To call a particular function in this situation, AviSynth's <tt>DLLName_function()</tt> feature automatically creates ''prefix aliases''; so for example, '''foo.dll''''s <tt>bar()</tt> function may be called as <tt>foo_bar()</tt>. This works both for auto-loaded plugins and for plugins loaded with [[LoadPlugin]].
  
Starting from v2.55 there is DLLName_function() support. The problem is that two plugins can have different functions which are named the same. To call the needed one, DLLName_function() support is added. It auto-generates the additional names both for auto-loaded plugins and for plugins loaded with LoadPlugin.
+
Suppose you have the plugins '''mpeg2dec.dll''' and '''mpeg2dec3.dll''' in your autoload directory; if you call
 +
<div {{BoxWidthIndent|38|1}} >
 +
mpeg2source("F:\From_hell\from_hell.d2v")
 +
</div>
 +
you won't know which plugin will be used in your script, as both have an <tt>mpeg2source</tt> function.
  
'''Some examples:'''
+
To load the file with [[External_plugins_old#Source_Filters|mpeg2dec.dll]] (which outputs [[YUY2]]), call
 
+
<div {{BoxWidthIndent|38|1}} >
# using fielddeinterlace from decomb510.dll
+
AviSource("D:\captures\jewel.avi")
+
decomb510_fielddeinterlace(blend=false)
+
 
+
Suppose you have  the plugins mpeg2dec.dll and mpeg2dec3.dll in your auto plugin dir, and you want to load a d2v file with mpeg2dec.dll (which outputs YUY2):
+
 
+
# using mpeg2source from mpeg2dec.dll
+
 
  mpeg2dec_mpeg2source("F:\From_hell\from_hell.d2v")
 
  mpeg2dec_mpeg2source("F:\From_hell\from_hell.d2v")
 +
</div>
 +
or to load the file with [[External_plugins_old#Source_Filters|mpeg2dec3.dll]] (which outputs [[YV12]]), call
 +
<div {{BoxWidthIndent|38|1}} >
 +
mpeg2dec{{BoldColor|blue|100|3}}_mpeg2source("F:\From_hell\from_hell.d2v")
 +
</div>
 +
</div>
  
or with mpeg2dec3.dll (which outputs YV12):
 
 
# using mpeg2source from mpeg2dec3.dll
 
mpeg2dec3_mpeg2source("F:\From_hell\from_hell.d2v")
 
  
 
----
 
----

Latest revision as of 12:03, 2 July 2018

With these functions you can add external filters (DLLs) to the AviSynth script environment.

Contents


[edit] LoadPlugin

Loads one or more standard (C++) AviSynth plugins.

LoadPlugin(string filename [, string filename...])

string  filename =
The path of the .DLL file(s).


[edit] LoadCPlugin

Loads so-called AviSynth C-plugins. C-plugins are created in pure C (unlike most Avisynth plugins, which are created with MS C++), use a special C API, and must be loaded with LoadCPlugin.

LoadCPlugin(string filename)
LoadCPlugin(string filename [, string filename...]) AVS+
Load_Stdcall_Plugin(string filename)
Load_Stdcall_Plugin(string filename [, string filename...]) AVS+

string  filename =
The path of the .DLL file(s).
  • The plugin's documentation should advise you if LoadCPlugin is needed.
  • Load_Stdcall_Plugin is merely an alias or alternate name.
  • Advice: keep these plugins outside your autoload directory to prevent crashes.


[edit] LoadVirtualDubPlugin

Loads a plugin written for VirtualDub. These are distributed as special DLLs with the file extension .VDF.

LoadVirtualDubPlugin (string filename, string filtername [, int preroll])

string  filename =
The path of the .VDF file.
string  filtername =
The name to be given to the plugin function after loading in AviSynth.
int  preroll = 0
Some filters' output depends on previous frames; for these, preroll should be set to a suitable number.

Note that there is a new parameter but _not_ for use in LoadVirtualdubPlugin, but when calling the loaded VDF filter from the script.

AVS+string  rangehint = ""
This extra filter parameter added at the end of filter's (unnamed) parameter list: string rangehint.
The imported Virtualdub filters (of course which are supporting the extra feature) are getting and extra named parameter to the end.
This parameter can tell the filter about a YUV-type clip colorspace info
Allowed values:
  • "rec601": limited range + 601
  • "rec709": limited range + 709
  • "PC.601": full range + 601
  • "PC.709": full range + 709
  • ""  : not defined (same as not given)
Parameter will be ignored when clip is non-YUV
How it works: the hint will _not_ change the internal VirtualDub colorspace constant (e.g. kPixFormat_YUV420_Planar -> kPixFormat_YUV420_Planar_709 will not happen).
Instead the base color space is kept and colorSpaceMode and colorRangeMode will set in PixmapLayout.formatEx.
Filter can either use this information or not, depending on supported API version and its implementation.
E.g. Crossfade(20,30) -> Crossfade(20,30,"rec601") (a bit stupid example, just for showing the syntax because this specific filter won't use it).
  • Supported color spaces and features:
  • VirtualDub filters originally support only RGB32.
  • AVS+ Since Avisynth+ r2724 LoadVirtualdubPlugin was updated to support newer interface versions.
This update changed the supported interface version from V6 to V20, and Filtermod version 6 (partial support)
Supported extras:
VirtualDub2 support with extended colorspaces
  • Allow RGB24, RGB48, RGB64 besides RGB32
  • RGBP/RGBAP 8 bit: since this format is not supported directly by Virtualdub filters, LoadVirtualdubPlugin automatically converts 8 bit Planar RGB to/from RGB24, RGBAP to/from RGB32 (lossless)
  • RGB48/RGBP16/RGBAP16: since this format is not supported directly by Virtualdub filters, LoadVirtualdubPlugin automatically converts them to/from RGB64 (lossless)
  • YUV(A) 8 bits: YV12, YV16, YV24, YV411, YUVA420P8, YUVA422P8, YUVA444P8
  • YUV(A) 10-16 bits (properly set "ref_x" maximum levels, no autoconvert)
  • Supports prefetchProc2 callback (API >= V14 and prefetchProc2 is defined) for multiple input frames from one input clip
  • PrefetchFrameDirect and PrefetchFrame are supported. PrefetchFrameSymbolic not supported
  • Supports prefetchProc callback (API >= V12 and prefetchProc is defined)
  • Supports when filter changes frame count of the output clip
  • Supports specifying some colorspace properties. See rangehint

[edit] LoadVFAPIPlugin

Loads VFAPI plugins (eg, QTReader, TMPGEnc). These are distributed as special DLLs with the file extension .VFP.

LoadVFAPIPlugin (string filename, string filtername)

string  filename =
The path of the .VFP file.
string  filtername =
The name to be given to the plugin function after loading in AviSynth.


[edit] Plugin Autoload and Name Precedence

It is possible to put all plugins and script files with user-defined functions or (global) variables in an autoload directory, from which all files with the extension .AVSI and .DLL are loaded at startup, then unloaded and reloaded dynamically as the script needs them.

.AVSI scripts in this directory should only contain function definitions and global variables; they should not have a main processing section (else strange errors may occur). It also is not recommended to put other files in that directory.

The directory is stored in the registry. You can use double-clicking a .REG-file with the following lines to set the path (of course inserting your actual path):

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth]
"plugindir2_5"="c:\\program files\\avisynth 2.5\\plugins"

The order in which function names take precedence is as follows:

  1. User-defined function (always have the highest priority)
  2. Plugin (external) function (higher priority than built-in)
  3. Built-in (internal) function

Inside those groups the function loaded last takes precedence; there is no error in a namespace conflict.
It follows that there is no harm in loading the same plugin more than once.[dubious – discuss]


[edit] Plugin Autoload and Conflicting Function Names

A problem that may arise when multiple plugins have functions with the same name. You won't know which function will be called in your script, as this will depend on loading order. To call a particular function in this situation, AviSynth's DLLName_function() feature automatically creates prefix aliases; so for example, foo.dll's bar() function may be called as foo_bar(). This works both for auto-loaded plugins and for plugins loaded with LoadPlugin.

Suppose you have the plugins mpeg2dec.dll and mpeg2dec3.dll in your autoload directory; if you call

mpeg2source("F:\From_hell\from_hell.d2v")

you won't know which plugin will be used in your script, as both have an mpeg2source function.

To load the file with mpeg2dec.dll (which outputs YUY2), call

mpeg2dec_mpeg2source("F:\From_hell\from_hell.d2v")

or to load the file with mpeg2dec3.dll (which outputs YV12), call

mpeg2dec3_mpeg2source("F:\From_hell\from_hell.d2v")



Back to AviSynth Syntax.

Personal tools