Home
RecentChanges

Search:

» AviSynth is a powerful video FrameServer for Win32.

AviSynth Links:
»Download
»Learn to script
»FAQ
»Manual
»Discussion fora
»Project page
»External filters
»FeedBack

» You can add pages to this website immediately. No login required.
Edit this document

» AboutAviSynth

 

Avisynth 
Logo

ScriptFunctions

( Diese Seite in flag-germany.gif Deutsch )

Script-Functions:

The input and output of these functions are not clips, but some other variables used in the script.

Numeric Functions:


Floor(float)

Converts from float to int (round down on any fractional amount).

Examples:

Floor(1.2) = 1
Floor(1.6) = 1
Floor(-1.2) = -2
Floor(-1.6) = -2

Ceil(float)

Converts from float to int (round up on any fractional amount).

Examples:

Ceil(1.2) = 2.0
Ceil(1.6) = 2.0
Ceil(-1.2) = -1
Ceil(-1.6) = -1

Round(float)

Converts from float to int (round off to nearest integer).

Examples:

Round(1.2) = 1
Round(1.6) = 2
Round(-1.2) = -1
Round(-1.6) = -2

Sin(float) v2


Cos(float) v2


Pi() v2


Log(float) v2


Exp(float) v2


Pow(float base, float power) v2


Sqrt(float) v2


Abs(float or integer) v2.07

Returns the absolute value (returns float for float, integer for integer).

Example:

Abs(-3.8) = 3.8

Sign(float) v2.07

Returns sign of value (1, 0 or -1).

Examples:

Sign(-3.5) = -1
Sign(3.5) = 1
Sign(0) = 0

Int(float) v2.07

Converts from float to int (round towards zero).

Examples:

Int(1.2) = 1
Int(1.6) = 1
Int(-1.2) = -1
Int(-1.6) = -1

Frac(float) v2.07

Returns the fractional portion of the value provided.

Examples:

Frac(3.7) = 0.7
Frac(-1.8) = -0.8

Float(int) v2.07

Converts int to float.


Value(string) v2.07

Converts string to numeric value.


HexValue(string) v2.07

Evaluates string as hexadecimal value.

Example:

HexValue ("FF00") = 65280

Rand([int max] [, bool scale] [, bool seed]) v2.07

Returns a random integer value and all parameters are optional. Max sets the maximum value+1 (default 32768) and can be set negative for negative results. It operates either in scaled or modulus mode (default scale=true only if abs(max) > 32768, false otherwise). Scaled mode scales the internal random number generator value to the maximum value, while modulus mode (scale=false) uses the remainder from an integer divide of the random generator value by the maximum. I found modulus mode is best for smaller maximums. Using Seed=true seeds the random number generator with the current time and defaults to false and probably isn't necessary, although it's there just in case. Typically, this function would be used with the Select function for random clips.

Example:

Select(Rand(5), clip1, clip2, clip3, clip4, clip5)

Spline(float X, x1, y1, x2, y2, .... [, bool cubic]) v2.51

Interpolates the Y value at point X using the control points x1/y1, ... There have to be at least 2 x/y-pairs. The interpolation can be cubic (the result is a spline) or linear (the result is a polygon).

Examples:

Spline(5, 0, 0, 10, 10, 20, 0, false) = 5
Spline(5, 0, 0, 10, 10, 20, 0, true) = 7

String Functions:


LCase(string) v2.07

Returns lower case of string.

Example:

LCase("AviSynth") = "avisynth"

UCase(string) v2.07

Returns upper case of string.

Example:

UCase("AviSynth") = "AVISYNTH"

StrLen(string) v2.07

Returns length of string.

Example:

StrLen("AviSynth") = 8

RevStr(string) v2.07

Returns string backwards.

Example:

RevStr("AviSynth") = "htnySivA"

LeftStr(string, int) v2.07

Returns first int number of characters.

Example:

LeftStr("AviSynth", 3) = "Avi"

RightStr(string, int) v2.07

Returns last int number of characters.

Example:

LeftStr("AviSynth", 5) = "Synth"

MidStr(string, int pos [, int length]) v2.07

returns substring starting at pos for optional length or to end. Pos=1 specifies start.

Example:

MidStr("AviSynth", 3, 2) = "iS"

FindStr(string, substring) v2.07

returns position of substring within string. Returns 0 if not found.

Example:

Findstr("AviSynth", "syn") = 4

String(float / int) v2

Converts a number to a string.

Example:

Subtitle( "Clip height is " + String(last.height) )

Chr(int) v2.51

Returns the ASCII character.

Example:

Chr(34) returns the quote character

Time(string) v2.51

Returns a string with the current system time formatted as defined by the string.Codes for output formatting:

%a Abbreviated weekday name

%A Full weekday name

%b Abbreviated month name

%B Full month name

%c Date and time representation appropriate for locale

%d Day of month as decimal number (01 – 31)

%H Hour in 24-hour format (00 – 23)

%I Hour in 12-hour format (01 – 12)

%j Day of year as decimal number (001 – 366)

%m Month as decimal number (01 – 12)

%M Minute as decimal number (00 – 59)

%p Current locale‚s A.M./P.M. indicator for 12-hour clock

%S Second as decimal number (00 – 59)

%U Week of year as decimal number, with Sunday as first day of week (00 – 53)

%w Weekday as decimal number (0 – 6; Sunday is 0)

%W Week of year as decimal number, with Monday as first day of week (00 – 53)

%x Date representation for current locale

%X Time representation for current locale

%y Year without century, as decimal number (00 – 99)

%YYear with century, as decimal number

%z, %Z Time-zone name or abbreviation; no characters if time zone is unknown

%% Percent sign

The # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows:

%#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#% # flag is ignored.

%#c Long date and time representation, appropriate for current locale. For example: “Tuesday, March 14, 1995, 12:41:29„.

%#x Long date representation, appropriate to current locale. For example: “Tuesday, March 14, 1995„.

%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y Remove leading zeros (if any).


Version Checking Functions:


VersionNumber() v2.07

Returns AviSynth version number as float.

Example:

VersionNumber() = 2.07

VersionString() v2.07

Returns AviSynth version info as string (first line used in Version command).

Example:

VersionString() = "AviSynth 2.08 (avisynth.org) 22 nov. 2002"

Variable Type and File Checking Functions:

IsBool(var)

IsInt(var)

IsFloat(var)

IsString(var)

IsClip(var)

Exist(filename) v2.07

Checks if specified file exists.

Defined(var): returns true if var defined, false otherwise.

Default(x,d): returns x if Defined(x), d otherwise.

Note: Defined and Default are primarily designed for dealing with optional declared variables in user-defined functions and are used to determine whether an optional variable has been passed. Any completely undeclared variable will generate an error. See "User Defined Functions" later in this section for more information.

Eval(string)

Apply(func-string, arg, ...): Eval("f(x)") is equivalent to f(x) is equivalent to Apply("f", x))

You can use Eval for something like:

settings = "352, 288"

Eval( "BicubicResize(" + settings + ")" )

You can import the text of another script:

Import (filename): evals contents of another AviSynth script.

For error reporting and catching bad input to user-defined function you can use (error-message if bool=false):

Assert (bool, string error-message)

There is a function for checking if an error WILL arise:

Try {

AviSource("file.avi")

}

catch(err_msg) {

Blackness.Subtitle(err_msg)

}

Control Functions:

SetMemoryMax(int): Sets the maximum memory that AviSynth uses (in MB). v2

In some versions there is a default setting of 5MB, which is quite low. If you encounter problems (e.g. low speed) try to set this values to at least 32MB.

SetWorkingDir(string): Sets the directory from which AviSource, LoadPlugin, etc. are referenced. This is primarily for easy loading of source clips, etc. Does not affect plugin autoloading. Return value: 0 if successful, -1 otherwise. v2

Conditional Operations:

[var=]boolean expression ? iftrue value or operation : ifelse value or operation

nop(): v2.07 null result primarily for if-then-else operation above where ifelse is not desired

(nop primarily to be used against non-variable / non-clip functions such as import and loadplugin)
Example:
versionnumber<2.07 ? import("patches.avs") : nop()

Select(int index, val item0 [,item1...]) <v2.07>

Indexed selection of item0 ... item<n-1> (no particular limit on number of items). Items can be of any type, including clips and technically, item types don't have to match, but that could be problematic. Can be used with Rand() function for the index to have a random clip generator or to manage various versions (i.e.,title, preview, main or perhaps PAL, NTSC, FILM) in the same script.

User defined functions:

You can define and call your own functions in AVS scripts as shown below. ScriptGrammar within a function is identical to that of a script at large. The function can return any clip or variable type. The format is generally as follows:

function function_name([var_type var_name [,...])
{
function commands
.
.
.
return(result)
}

Curled brackets must enclose the function commands, but they can share lines with the function header and / or the first and last function commands. The following is an example of a single line function:

function rednum(clip c, int "num") { return subtitle(c,string(default(num,0)),text_color=$FF0000) }

Variables passed to functions can be made optional by enclosing var_name in quotes (i.e., int "num" in the previous example). Within the function, you would include a Defined or Default function to determine if var_name was passed and set the default value or alter your processing accordingly. Optional parameters can also be called using the var_name=value syntax to skip over other optional parameters.

function NTSC2PAL(clip c) {
 # Fairly good NTSC->PAL conversion.  Would be better with Smart Bob. :-)
 Assert(c.height == 480, "NTSC2PAL: input clip must have 480 scan lines")
 Bob(c, height=576)
 ChangeFPS(50)
 SeparateFields.SelectEvery(4, 0, 3)
 return Weave
}

AviSource("ntsc.avi").NTSC2PAL

If you create anything cool, be sure to post it to ShareFunctions!

Back to AviSynthManual

SourceForge Logo

 


Edit this document | View document history
Document last modified Sun, 11 Jan 2004 15:32:21