AviSynth#"Hello World"

{{Short description|Computer frameserver program}}

{{Refimprove|date=November 2009}}

{{Infobox software

| name = AviSynth

| logo =

| logo caption = AviSynth logo

| screenshot =

| caption = A powerful A/V Frameserver

| developer = AviSynth developers, Doom9 community

| programming language = C++, Assembly

| operating_system = Windows, Linux, macOS

| genre = Digital video frameserver

| license = GNU GPL

| website = {{URL|http://www.avisynth.nl}}

| released = {{Start date and age|2000|05|19|df=yes}}

| platform = x86 and x86-64

}}

AviSynth is a frameserver program for Microsoft Windows, Linux and macOS initially developed by Ben Rudiak-Gould, Edwin van Eggelen, Klaus Post, Richard Berg and Ian Brabham in May 2000{{cite web|title=Avisynth Copyright|url=http://avisynth.nl/index.php/Avisynth_wiki:Copyrights|work=AviSynth Mediawiki|publisher=AviSynth Team|accessdate=11 September 2015}} and later picked up and maintained by the open source community which is still active nowadays. It is free software licensed under the GNU General Public License.

Scripting video editor

AviSynth acts as a non-linear video editor controlled entirely by scripting (without a GUI).{{cite web|title=Main Page - Avisynth|url=http://avisynth.nl/index.php/Main_Page|work=AviSynth Mediawiki|publisher=AviSynth Team|accessdate=10 April 2013}} It emulates an AVI video file (or WAV audio file) as seen by the VFW downstream application, which is typically a media player, video editing software, or an encoder.{{cite web|title=More about AviSynth - Avisynth|url=http://avisynth.nl/index.php/More_about_AviSynth|work=AviSynth Wiki|publisher=AviSynth Team|accessdate=10 April 2013}}

AviSynth is built upon filters, which are much like DirectShow filters, but with a different binary interface. Filter capabilities include cropping, deinterlacing, inverse telecine, working with still images, doing basic color grading, reducing video noise, and many other things. AviSynth also performs traditional video editing tasks like cutting, trimming and re-sequencing segments.

For example, consider the script "myAvi.avs" (just a plain text-file saved with the extension "avs")

AviSource("myAvi.avi")

Crop(0, 0, 320, 240)

Blur(0.1)

This script file can be opened in most media players (such as Windows Media Player). The program will play the video file "myAvi.avi" cropped down to its top-left 320 pixels by 240 pixels and blurred by a small amount. Operations occur in sequential order, so the cropping occurs first, then the blurring.

Technically, AviSynth constructs a filter graph (like Microsoft GraphEdit but with added capabilities),{{cite web|title=The Script Execution Model: The Filter Graph|url=http://avisynth.nl/index.php/The_script_execution_model/The_filter_graph|work=AviSynth Wiki|publisher=AviSynth Team|accessdate=25 October 2019}} controlled by scripts written in the [http://avisynth.nl/index.php/Grammar AviSynth scripting language]. Its functionality can be extended through the use of third-party filters known as plugins. An external plugin list is maintained at [http://avisynth.nl/index.php/External_filters AviSynth Filter Collection].

AviSynth is a frameserver – the calling program requests audio/video frames and the script serves them. The calling program can call frames in any order, allowing it to pause, jump forward or backward etc., just as with a physical file.

AviSynth scripting language

The scripting language is a dataflow language: a programming paradigm that describes a directed graph of the data flowing between operations. It lacks some procedural programming control structures,{{cite web|url=http://avisynth.nl/index.php/Control_structures |title=AviSynth syntax: control structures |work=AviSynth Wiki |publisher=Avisynth Team|accessdate=Sep 21, 2014}} but it contains many features familiar to programmers, including variables, distinct datatypes, conditionals, and complex expressions.

The language works primarily with the audio/video clip as a built-in data type. The clip is a complex structure with many attributes such as width, height and duration.{{cite web|url=http://avisynth.nl/index.php/Clip_properties |title=Clip Properties |work=AviSynth Wiki |publisher=Avisynth Team|accessdate=Oct 27, 2019}} The language also has several other more standard data types: int, float, bool and string.{{cite web|url=http://avisynth.nl/index.php/Script_variables |title=Script Variables |work=AviSynth Wiki |publisher=Avisynth Team|accessdate=Sep 14, 2017}} These can be used to perform calculations, decisions, and write text such as subtitles to the video.

The script has a single return value, which is the audio and video 'seen' by the program running the script. This is normally the last line of the script, but a return statement may be inserted at any point.

="Hello World"=

This example is a "Hello World" program.

BlankClip()

Subtitle("Hello, world!")

If the above text is entered into a text file with the .avs extension, it can be opened in Windows Media Player or any of the other programs in the list below, and a video containing the words "Hello, world!" will be displayed.

The {{mono|BlankClip}} function creates a new video. The parentheses at the end of the word are optional, since no arguments are being passed, but are given in this case to indicate it is a function and not a variable.

The {{mono|Subtitle}} function draws the words "Hello, world!" on top of the previously-created blank video.

Although both functions both accept many more arguments (for example, controlling the size and length of the blank video, and the positioning, font, and color of the subtitle), this example leaves them out; the functions use built-in default arguments.

Avisynth uses syntactic sugar that makes simple scripts far easier to write: an implicit variable called {{mono|Last}}. Without implicit variables, the above script would have to be written like this:

Last = BlankClip()

Last = Last.Subtitle("Hello, world!")

return Last

or like this:

A = BlankClip()

B = A.Subtitle("Hello, world!")

return B

Explicit clip variables are normally only used for functions involving more than one clip:

A = BlankClip()

B = A.Subtitle("Hello, world!")

return Dissolve(A, B, 30) # 30-frame cross fade

=Video-processing=

This example takes an actual video, applies some simple processing, and returns it to the output.

AviSource("C:\Example.avi")

ReduceBy2()

GreyScale()

The {{mono|AviSource}} function is used to load an AVI video from a real location. To open other media types, the {{mono|DirectShowSource}} function could be used instead. {{mono|ReduceBy2}} divides the vertical and horizontal size of the video in half, and {{mono|GreyScale}} removes all color information.

AviSynth filters work in many RGB and YUV color spaces to allow all kinds of video input and output.{{cite web|title=Convert - Avisynth|url=http://avisynth.nl/index.php/Convert|work=AviSynth Wiki|publisher=AviSynth Team|accessdate=27 October 2019}} Certain functions only work on specific color spaces, requiring conversion – for example, most videos are distributed in a YUV color space, but most color correction is done in one of the RGB spaces. A color-correcting script might look like this:

DirectShowSource("movie.mp4") # YV12 color space

ConvertToRGB32

RGBAdjust(1.0, 0.95, 1.0) # decrease Green channel

ConvertToYV12

=User defined=

The AviSynth scripting language allows for users to define their own functions.

This is an example of a function that allows you to dissolve from one clip to another without damaging interlacing lines.

clip1 = AVISource("video1.avi")

clip2 = AVISource("video2.avi")

# call the user-defined function which is defined below:

interlaced_dissolve(clip1, clip2, 30)

# ...the script returns the above result to the calling program

# user-defined function:

# dissolve from clip1 to clip2 over 30 frames

function interlaced_dissolve(clip clip1, clip clip2, int iter) {

clip1 = clip1.SeparateFields

evn1 = clip1.SelectEven

odd1 = clip1.SelectOdd

clip2 = clip2.SeparateFields

evn2 = clip2.SelectEven

odd2 = clip2.SelectOdd

evn = Dissolve(evn1, evn2, iter)

odd = Dissolve(odd1, odd2, iter)

Interleave(evn, odd).Weave.DoubleWeave.SelectOdd

# ...the function returns the above result to the main script

}

AviSynth 3.0 and AviSynth+

AviSynth 3.0 was a complete rewrite of AviSynth 2.x, and aimed to overcome the limitations of AviSynth 2.x.

Adding improvements such as an abstracted color space model, in which new color spaces (including two with 45-bit depth) could be supported through a plug-in mechanism, better cache management for better performance, and using Ruby rather than the homegrown language employed in current versions.{{cite web|url=http://forum.doom9.org/showthread.php?t=140376|title=Avisynth 3 - dead project? |website=Doom9 Forum |accessdate=2009-06-17}}

AviSynth 3.0 was to be available for other operating systems than Windows, instead relying on GStreamer, extending support to platforms such as Linux, Mac OS X and BSD. Development has been stalled since August 2007.{{cite web

|url=http://avisynth.nl/index.php/AviSynth_v3#Q5.29_How_many_developers_are_working_on_it.3F

|title=AviSynth v3

|work=AviSynth Mediawiki

|accessdate=22 September 2019}}

[https://github.com/AviSynth/AviSynthPlus AviSynth+] is a fork of the official AviSynth 2.xx, introducing long-sought features such as 64-bit support, multithreading, deep color spaces, support for recent compilers, new scripting constructs (new control-flow constructs such as loops), and increased performance in many areas.{{cite web

|url=http://avisynth.nl/index.php/AviSynth%2B

|title=AviSynth+

|work=AviSynth Mediawiki

|access-date=22 September 2019

}} At the same time it retained 100% compatibility to the AviSynth 2.5/2.6 series, both for filters and host applications. At the time of writing (2023-06), it is also actively maintained.

AviSynth for non-Windows operating systems

AviSynth 2.xx may be used under operating systems other than Windows through the use of Wine. To work on scripts VirtualDub/VirtualDubMod can be used as on Windows. To interface between AviSynth under Wine and for example FFmpeg running on a Linux host, Avs2YUV can be used. Avs2YUV is a Windows command line program that is run under Wine and renders the output of an AviSynth script to stdout that is then piped to FFmpeg. Avs2YUV also supports writing to a named pipe.{{cite web|url=http://akuvian.org/src/avisynth/avs2yuv/|title=Avs2YUV|work=Akuvian.org|accessdate=2011-01-09}}

There is a Linux port of AviSynth called AvxSynth.{{cite web|url=https://github.com/avxsynth/avxsynth|title=avxsynth/avxsynth: Linux Port of Avisynth|work=GitHub|accessdate=2017-09-16}}

AviSynth compatible programs

class="wikitable sortable"
Program nameLicenseclass="unsortable" | Commentsclass="unsortable" | Homepage
Adobe Premiere Pro

| Proprietary, commercial

| Version 6.0 and later (up to and including CS4) have an AviSynth import plugin available.

| [http://videoeditorskit.sourceforge.net/ Premiere AviSynth import plugin]

Avanti GUI

| Proprietary, freeware

| Avanti GUI is a free front-end for FFmpeg with the option to insert AviSynth as pre-processor.

| [http://avanti.arrozcru.org/ Avanti GUI]

AvsPmod

| GPL

| AvsPmod is AviSynth script editor with builtin player, syntax highlighting and code autocompletion.

| [https://avspmod.github.io/ AvsPmod]

Cinema Craft Encoder

| Proprietary

| Cinema Craft Encoder is a commercial MPEG-2 encoder that supports AviSynth input.

| [http://www.cinemacraft.com Cinema Craft]

FFmpeg

| LGPL2.1+, GPL 2+

| FFmpeg compiled for Windows can receive AviSynth input

| [https://ffmpeg.org/faq.html#How-can-I-read-DirectShow-files_003f instructions]

GOM Player

| Proprietary, freeware, ad-supported

| Can play .avs files

|

Media Player Classic

| GPL

| Media Player Classic is capable of loading and playing AviSynth scripts. The 32-bit version is needed.

| [http://sourceforge.net/projects/guliverkli/ Media Player Classic]

Microsoft Expression Encoder

| Proprietary, freemium

| Microsoft Expression Encoder can import and transcode .avs files.

|

MPlayer

| GPL

| MPlayer can play .avs files

|

Nero Multimedia Suite

| Proprietary, commercial

| Nero Showtime can play .avs files

|

SUPER

| Proprietary, freeware, ad-supported

| SUPER (Simplified Universal Player, Encoder and Renderer) is freeware from eRightSoft that can encode most common video formats and has full AviSynth support.

| [http://www.erightsoft.com/SUPER.html SUPER]

TMPGEnc

| Shareware/freeware

| TMPGEnc is a free MPEG-1 and MPEG-2 encoder. TMPGEnc Plus and TMPGEnc Express are commercial versions of TMPGEnc that include enhanced functionality, as well as the removal of a 30-day restriction on MPEG-2 encoding present in TMPGEnc.

| [http://www.pegasys-inc.com Pegasys Inc.]

Total video converter

| Proprietary, trialware

| Total video converter has an AviSynth import plugin available.

| [http://www.effectmatrix.com/total-video-converter Total Video Converter]

VirtualDub

| GPL

| VirtualDub is a widely used all-purpose video converter.

| [http://www.virtualdub.org/ VirtualDub]

VirtualDubMod

| GPL

| VirtualDubMod contains several AviSynth-specific features such as explicit support for AviSynth scripts, an AviSynth script editor, and more. However, it has not been updated since 2006 and contains many bugs.{{cite web|url=http://sourceforge.net/tracker/?group_id=65889&atid=512619|title= SourceForge.net: VirtualDubMod: Bugs |accessdate=2009-12-03}}

| [http://virtualdubmod.sourceforge.net VirtualDubMod]

Windows Media Player

| Proprietary, component of Windows / freeware

| Windows Media Player is capable of loading and playing AviSynth scripts, so it is a good choice for simple playback and testing. It may require some registry tweaks to get it working.

| [http://www.microsoft.com/windows/windowsmedia/ Windows Media Home]

In addition, several programs have now been created which accept only AviSynth scripts as input - thereby simplifying the programs themselves but giving users the full power of AviSynth for input.

There are also several batch encoding applications that tie together AviSynth with command line audio and video encoders and muxers to provide an all-in-one, modular, customizable video encoding application. MeGUI is an example of this kind of application.

Although AviSynth scripts are meant to be easily opened in simple text editing programs, there are several editors meant especially for editing AviSynth scripts such as [http://forum.doom9.org/showthread.php?t=153248 AvsPMod].

{{Expand section|date=May 2008}}

See also

References

{{Reflist}}