Filter SDK

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Writing utilities that access AviSynth)
(Processing video)
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
AviSynth external Filter SDK is a package for developers to create your own filters (plugins) for AviSynth.
+
AviSynth external Filter SDK is a package for developers to create your own filters (plugins and console applications) for AviSynth.
  
 
The package consists of:
 
The package consists of:
  
 
* this documentation text files (in HTML or Wiki format);
 
* this documentation text files (in HTML or Wiki format);
* the header file 'avisynth.h' (recent version) with all declarations to include in plugin source code;
+
* the header files 'avisynth.h' (for the use of the C++ API) and 'avisynth_c.h' (for the use of the C API) with all declarations to include in plugin source code;
* SimpleSample plugin source codes;
+
* avisynth.lib (for the use of the C API);
* may be some extra files in 'Extra' folder.
+
* several plugin and console application source codes;
 +
* some extra files in 'Extra' folder.
  
 
== Necessary software ==
 
== Necessary software ==
  
You must have some [[Filter_SDK/SDK_necessaries|necessary software]].
+
You must have some [[Filter_SDK/SDK_necessaries|necessary software]] and [[Filter_SDK/Compile AviSynth|necessary software and setting up environments]].
  
 
== Writing a plugin ==
 
== Writing a plugin ==
  
We will start by writing some simple plugins to show you the basics.
+
We will start by writing some simple plugins to show you the basics. All plugins use the C++ API unless stated otherwise.
  
 
=== Processing video ===
 
=== Processing video ===
  
* [[Filter_SDK/InvertNeg|InvertNeg]] produces a photo-negative of the input clip.
+
* [[Filter_SDK/InvertNeg|InvertNeg]] (or [[Filter_SDK/CInvertNeg|InvertNeg]] using the C API) produces a photo-negative of the input clip.
* [[Filter_SDK/SimpleSample|SimpleSample]] has some very simple examples covering development of a filter that draws a variable sized square, in the middle of the screen. It does so for all color formats.
+
* [[Filter_SDK/SimpleSample|SimpleSample]] draws a variable sized square in the middle of the screen. It does so for all color formats.
 +
* [[Filter_SDK/CMerge|Merge]] (using the C API) merges two clips using a weight.
  
 
One thing not covered in the examples, is how to [[Filter_SDK/Change_frame_size|change frame size]] in a filter.
 
One thing not covered in the examples, is how to [[Filter_SDK/Change_frame_size|change frame size]] in a filter.
Line 25: Line 27:
 
=== Processing audio ===
 
=== Processing audio ===
  
* xxx
+
See [[Filter_SDK/Cplusplus_API#GetAudio|Cplusplus API: GetAudio]] and
 
+
[[Filter_SDK/Getting_started_with_audio|Filter SDK: Getting started with audio]].
Also have a look at [[Filter_SDK/Getting_started_with_audio|Getting started with Audio]].
+
  
 
=== Runtime functions ===
 
=== Runtime functions ===
Line 35: Line 36:
 
=== Source filters ===
 
=== Source filters ===
  
xxx
+
* [[Filter_SDK/GradientMask|GradientMask]] creates a simple Gradient. The example explains a few things how source filters work.
  
 
=== Speeding up your plugin using assembler ===
 
=== Speeding up your plugin using assembler ===
  
You can also browse various topic on [[Filter_SDK/Assembler_optimizing|Assembler Optimizing]].
+
You can also browse various topics on [[Filter_SDK/Assembler_optimizing|Assembler Optimizing]].
  
 
=== Making dual plugins ===
 
=== Making dual plugins ===
Line 46: Line 47:
  
 
There are several ways to make 2.6 plugins (plugins compiled with plugin api v5 or higher) also work with AviSynth 2.5. They are described [[Filter_SDK/DualPlugins|here]].
 
There are several ways to make 2.6 plugins (plugins compiled with plugin api v5 or higher) also work with AviSynth 2.5. They are described [[Filter_SDK/DualPlugins|here]].
 +
 +
=== Miscellaneous ===
 +
 +
There are several different Colorspaces in AviSynth. See more information about [[Color_spaces|Color spaces]] and [[Filter_SDK/Working_with_images|Working with Images]].
 +
 +
Read more about the [[Filter_SDK/Internal_functions|Internal Functions]] in AviSynth.
  
 
== Writing utilities that access AviSynth ==
 
== Writing utilities that access AviSynth ==
Line 53: Line 60:
 
The first one is to use the VfW api (using the [http://msdn.microsoft.com/en-us/library/windows/desktop/dd756808%28v=vs.85%29.aspx AVIFile library]) like is done in avs2avi (see [http://forum.doom9.org/showthread.php?t=71493] or [http://www.avisynth.info/?%A5%A2%A1%BC%A5%AB%A5%A4%A5%D6#t952b3b1]), avs2yuv ([http://komisar.gin.by/tools/avs2yuv/avs2yuv-0.24bm2.zip using the C api], or [http://kemuri9.net/dev/avs/avs2yuv/avs2yuv.zip using the C++ api]), or [http://forum.doom9.org/showthread.php?p=1502613#post1502613 avs2wav] for example. See also [http://forum.doom9.org/showthread.php?p=589781#post589781 here] to get you going.
 
The first one is to use the VfW api (using the [http://msdn.microsoft.com/en-us/library/windows/desktop/dd756808%28v=vs.85%29.aspx AVIFile library]) like is done in avs2avi (see [http://forum.doom9.org/showthread.php?t=71493] or [http://www.avisynth.info/?%A5%A2%A1%BC%A5%AB%A5%A4%A5%D6#t952b3b1]), avs2yuv ([http://komisar.gin.by/tools/avs2yuv/avs2yuv-0.24bm2.zip using the C api], or [http://kemuri9.net/dev/avs/avs2yuv/avs2yuv.zip using the C++ api]), or [http://forum.doom9.org/showthread.php?p=1502613#post1502613 avs2wav] for example. See also [http://forum.doom9.org/showthread.php?p=589781#post589781 here] to get you going.
  
The second one is to call AviSynth directly like is done in [http://forum.doom9.org/showthread.php?t=160383 avs2pipe] for example (it uses the C api). It's a tool to output y4m video or wav audio. The way to do this is importing avisynth.dll via loadlibrary() and getprocaddress(). Then creating a scriptenvironment and importing a script using invoke(). At that point you will have a clip from which you can call getframe() to access the video and getaudio() to access the audio.
+
The second one is to call AviSynth directly like is done in [http://forum.doom9.org/showthread.php?t=160383 avs2pipe] for example (it uses the C api). It's a tool to output y4m video or wav audio to stdout. The way to do this is importing avisynth.dll via loadlibrary() and getprocaddress(). Then creating a scriptenvironment and importing a script using invoke(). At that point you will have a clip from which you can call getframe() to access the video and getaudio() to access the audio.
  
 
Below are some examples that have a script as input and raw video or audio as output:
 
Below are some examples that have a script as input and raw video or audio as output:
Line 59: Line 66:
 
* [[Filter_SDK/avs2yuv|avs2yuv]] reads a script and outputs raw video.
 
* [[Filter_SDK/avs2yuv|avs2yuv]] reads a script and outputs raw video.
 
* [[Filter_SDK/avs2pcm|avs2pcm]] reads a script and outputs raw audio.
 
* [[Filter_SDK/avs2pcm|avs2pcm]] reads a script and outputs raw audio.
 
== What's new in the 2.6 api ==
 
 
...
 
  
 
== AviSynth and its plugin api's ==
 
== AviSynth and its plugin api's ==
Line 72: Line 75:
 
AviSynth has the capability to load third-party libraries that include their own video and audio filters. It comes with two language interfaces (or plugin api's):
 
AviSynth has the capability to load third-party libraries that include their own video and audio filters. It comes with two language interfaces (or plugin api's):
  
* C++ API (through avisynth.h) - The classes and miscellaneous constants are described in [[Cplusplus_API|here]].
+
* C++ API (through avisynth.h) - The classes and miscellaneous constants are described in [[Filter_SDK/Cplusplus_API|here]].
* C API (through avisynth_c.h) - The classes and miscellaneous constants are described in [[C_API|here]].
+
* C API (through avisynth_c.h) - The classes and miscellaneous constants are described in [[Filter_SDK/C_API|here]].
 
+
Although not included in AviSynth itself, several people wrote other language interfaces in Delphi, Purebasic, NET and Java. They can be found [http://forum.doom9.org/showthread.php?p=566904#post566904 here].
+
  
 
The built-in filters use the C++ API. This Filter SDK (or Source Development Kit) describes how to create plugins using both interfaces.  
 
The built-in filters use the C++ API. This Filter SDK (or Source Development Kit) describes how to create plugins using both interfaces.  
  
...
+
Although not included in AviSynth itself, several people wrote other language interfaces in Delphi, Purebasic, NET and Java. They can be found [http://forum.doom9.org/showthread.php?p=566904#post566904 here].
  
There are several different Colorspaces in AviSynth. See more information about [[Color_spaces|Color spaces]] and [[Filter_SDK/Working_with_images|Working with Images]].
+
== What's new in the 2.6 api ==
  
Read more about the [[Filter_SDK/Internal_functions|Internal Functions]] in AviSynth.
+
* C++ API (AVISYNTH_INTERFACE_VERSION = 6):
 +
** Plugin api v3 and older contained [[Filter_SDK/AVS_Linkage|baked code]] meaning code that is "baked" into all and every plugin instead being called from avisynth.dll. Starting from 2.6 the version 2.5 plugins are supported directly (with current baked code; meaning that plugins compiled for 2.5 can be loaded when using 2.6) and all the baked code from 2.6+ plugins is removed and the plugins are still source compatible. Note that the baked code is moved to interface.cpp, where also the structure [[Filter_SDK/AVS_Linkage|AVS_Linkage]] is defined.
 +
** The [[Filter_SDK/Cplusplus_API#IScriptEnvironment|IScriptEnvironment]] interface has several new members:
 +
*** [[Filter_SDK/Cplusplus_API#ApplyMessage.2C_v5|ApplyMessage]] writes text on a frame.
 +
*** [[Filter_SDK/Cplusplus_API#DeleteScriptEnvironment|DeleteScriptEnvironment]] provides a method to delete the ScriptEnvironment which is created with CreateScriptEnvironment.
 +
*** [[Filter_SDK/Cplusplus_API#GetAVSLinkage_.2C_v5|GetAVSLinkage]] returns the AVSLinkage.
 +
*** [[Filter_SDK/Cplusplus_API#GetVarDef.2C_v6|GetVarDef]] can be used to access AviSynth variables. It will not throw an error if the variable doesn't exist.
 +
** It uses size_t for things that are memory sizes, ready for 64 bit port.
 +
** New colorformats are added: Y8, YV411, YV16 and YV24.
 +
** [[Filter_SDK/Cplusplus_API/VideoInfo|VideoInfo]] has several new constants and functions (the ones relating to the new colorformats, the chroma placement constants, GetPlaneHeightSubsampling, GetPlaneWidthSubsampling).
 +
** Some new cache and cpu constants for GetCPUFlags (the v5/v6 ones).
 +
** SetCacheHints changed from void to int.
  
...
+
* C API (AVISYNTH_INTERFACE_VERSION = 6):
 +
** The following functions are added to the interface: avs_is_yv24, avs_is_yv16, avs_is_yv12, avs_is_yv411, avs_is_y8, avs_is_color_space, avs_get_plane_width_subsampling, avs_get_plane_height_subsampling, avs_bits_per_pixel, avs_bytes_from_pixels, avs_row_size, avs_bmp_size, avs_get_row_size_p, avs_get_height_p and avs_delete_script_environment.
  
 
== Some history ==
 
== Some history ==
Line 101: Line 114:
  
 
Some video related ebooks (PDF) can be downloaded freely from [http://www.snellwilcox.com/reference.html Snell & Wilcox]. edit - http://www.snellgroup.com/support/documentation/engineering-guides this???
 
Some video related ebooks (PDF) can be downloaded freely from [http://www.snellwilcox.com/reference.html Snell & Wilcox]. edit - http://www.snellgroup.com/support/documentation/engineering-guides this???
 
  
 
== License terms ==
 
== License terms ==

Latest revision as of 23:00, 28 December 2016

AviSynth external Filter SDK is a package for developers to create your own filters (plugins and console applications) for AviSynth.

The package consists of:

  • this documentation text files (in HTML or Wiki format);
  • the header files 'avisynth.h' (for the use of the C++ API) and 'avisynth_c.h' (for the use of the C API) with all declarations to include in plugin source code;
  • avisynth.lib (for the use of the C API);
  • several plugin and console application source codes;
  • some extra files in 'Extra' folder.

Contents

[edit] Necessary software

You must have some necessary software and necessary software and setting up environments.

[edit] Writing a plugin

We will start by writing some simple plugins to show you the basics. All plugins use the C++ API unless stated otherwise.

[edit] Processing video

  • InvertNeg (or InvertNeg using the C API) produces a photo-negative of the input clip.
  • SimpleSample draws a variable sized square in the middle of the screen. It does so for all color formats.
  • Merge (using the C API) merges two clips using a weight.

One thing not covered in the examples, is how to change frame size in a filter.

[edit] Processing audio

See Cplusplus API: GetAudio and Filter SDK: Getting started with audio.

[edit] Runtime functions

See Non-clip sample how to create runtime AviSynth functions.

[edit] Source filters

  • GradientMask creates a simple Gradient. The example explains a few things how source filters work.

[edit] Speeding up your plugin using assembler

You can also browse various topics on Assembler Optimizing.

[edit] Making dual plugins

One of the features of AviSynth 2.6 is that 2.5 plugins (plugins compiled with plugin api v3) can still be used in AviSynth 2.6, although you need to make sure you use it properly since it doesn't know about the new features in AviSynth 2.6. So when processing a clip (with say color format YV16) with a 2.5 plugin you will get a messed up clip at best, and a crash at worst, since YV16 is not supported in the v3 api.

There are several ways to make 2.6 plugins (plugins compiled with plugin api v5 or higher) also work with AviSynth 2.5. They are described here.

[edit] Miscellaneous

There are several different Colorspaces in AviSynth. See more information about Color spaces and Working with Images.

Read more about the Internal Functions in AviSynth.

[edit] Writing utilities that access AviSynth

When writing console applications (commandline programs) it is possible to access AviSynth in two ways.

The first one is to use the VfW api (using the AVIFile library) like is done in avs2avi (see [1] or [2]), avs2yuv (using the C api, or using the C++ api), or avs2wav for example. See also here to get you going.

The second one is to call AviSynth directly like is done in avs2pipe for example (it uses the C api). It's a tool to output y4m video or wav audio to stdout. The way to do this is importing avisynth.dll via loadlibrary() and getprocaddress(). Then creating a scriptenvironment and importing a script using invoke(). At that point you will have a clip from which you can call getframe() to access the video and getaudio() to access the audio.

Below are some examples that have a script as input and raw video or audio as output:

  • avs2yuv reads a script and outputs raw video.
  • avs2pcm reads a script and outputs raw audio.

[edit] AviSynth and its plugin api's

AviSynth exists as an instance of the ScriptEnvironment class, that implements the IScriptEnvironment interface. The IScriptEnvironment interface is defined in avisynth.h (and avisynth_c.h) and it is the only way for plugins and external applications to communicate with AviSynth. A pointer to ScriptEnvironment object is passed along to all plugins, so that they can use AviSynth facilities. Plugins are forbidden from storing this pointer. AviSynth creates one ScriptEnvironment object when Windows attempts to use AviSynth to open a script via AVIFile API.

When ScriptEnvironment is created, it checks for CPU extensions (to provide this information to filters that are able to use CPU extensions), sets up memory limits for itself and performs pre-scanning of all plugins.

AviSynth has the capability to load third-party libraries that include their own video and audio filters. It comes with two language interfaces (or plugin api's):

  • C++ API (through avisynth.h) - The classes and miscellaneous constants are described in here.
  • C API (through avisynth_c.h) - The classes and miscellaneous constants are described in here.

The built-in filters use the C++ API. This Filter SDK (or Source Development Kit) describes how to create plugins using both interfaces.

Although not included in AviSynth itself, several people wrote other language interfaces in Delphi, Purebasic, NET and Java. They can be found here.

[edit] What's new in the 2.6 api

  • C++ API (AVISYNTH_INTERFACE_VERSION = 6):
    • Plugin api v3 and older contained baked code meaning code that is "baked" into all and every plugin instead being called from avisynth.dll. Starting from 2.6 the version 2.5 plugins are supported directly (with current baked code; meaning that plugins compiled for 2.5 can be loaded when using 2.6) and all the baked code from 2.6+ plugins is removed and the plugins are still source compatible. Note that the baked code is moved to interface.cpp, where also the structure AVS_Linkage is defined.
    • The IScriptEnvironment interface has several new members:
      • ApplyMessage writes text on a frame.
      • DeleteScriptEnvironment provides a method to delete the ScriptEnvironment which is created with CreateScriptEnvironment.
      • GetAVSLinkage returns the AVSLinkage.
      • GetVarDef can be used to access AviSynth variables. It will not throw an error if the variable doesn't exist.
    • It uses size_t for things that are memory sizes, ready for 64 bit port.
    • New colorformats are added: Y8, YV411, YV16 and YV24.
    • VideoInfo has several new constants and functions (the ones relating to the new colorformats, the chroma placement constants, GetPlaneHeightSubsampling, GetPlaneWidthSubsampling).
    • Some new cache and cpu constants for GetCPUFlags (the v5/v6 ones).
    • SetCacheHints changed from void to int.
  • C API (AVISYNTH_INTERFACE_VERSION = 6):
    • The following functions are added to the interface: avs_is_yv24, avs_is_yv16, avs_is_yv12, avs_is_yv411, avs_is_y8, avs_is_color_space, avs_get_plane_width_subsampling, avs_get_plane_height_subsampling, avs_bits_per_pixel, avs_bytes_from_pixels, avs_row_size, avs_bmp_size, avs_get_row_size_p, avs_get_height_p and avs_delete_script_environment.

[edit] Some history

Ben's AviSynth Docs is the documentation written for AviSynth 1.0 by Ben Rudiak-Gould, in its original form.

See more about the modifications for AviSynth 2.5 in the AviSynth Two-Five SDK.

Please read AviSynth SDK History. ---

[edit] Other sources ???

Once you've got the basics down on AVS development (Ben's text is quite good), the SDK for VirtualDub is also a good read. Good news is you won't have to worry about writing function pointers and raw Win32; meanwhile, Avery knows his stuff when it comes to video & CPU optimization techniques, so you better pay attention.

Some video related ebooks (PDF) can be downloaded freely from Snell & Wilcox. edit - http://www.snellgroup.com/support/documentation/engineering-guides this???

[edit] License terms

Note: Avisynth Filter SDK parts are under specific SDK license terms.

Personal tools