( Diese Seite in
Deutsch )
The input and output of these functions are not clips, but some other variables used in the script.
MulDiv(int, int, int) v2.56
(m*n+d/2)/d with 64 bit intermediate result
Examples:
Floor(float)
Converts from float to int (round down on any fractional amount).
Examples:
Ceil(float)
Converts from float to int (round up on any fractional amount).
Examples:
Round(float)
Converts from float to int (round off to nearest integer).
Examples:
Sin(float) v2
Returns the sine of the argument (assumes it is radians).
Examples:
Cos(float) v2
Returns the cosine of the argument (assumes it is radians).
Examples:
Pi() v2
Returns the value of the "pi" constant (the ratio of a circle's perimeter to its diameter).
Examples:
Log(float) v2
Returns the natural (base-e) logarithm of the argument.
Examples:
Exp(float) v2
Returns the natural (base-e) exponent of the argument.
Examples:
Pow(float base, float power) v2
Returns "base" raised to the power indicated by the second argument.
Examples:
Sqrt(float) v2
Returns the square root of the argument.
Examples:
Abs(float or integer) v2.07
Returns the absolute value (returns float for float, integer for integer).
Example:
Sign(float) v2.07
Returns sign of value (1, 0 or -1).
Examples:
Int(float) v2.07
Converts from float to int (round towards zero).
Examples:
Frac(float) v2.07
Returns the fractional portion of the value provided.
Examples:
Float(int) v2.07
Converts int to float.
Value(string) v2.07
Converts string to numeric value.
Example:
HexValue(string) v2.07
Evaluates string as hexadecimal value.
Example:
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:
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:
LCase(string) v2.07
Returns lower case of string.
Example:
UCase(string) v2.07
Returns upper case of string.
Example:
StrLen(string) v2.07
Returns length of string.
Example:
RevStr(string) v2.07
Returns string backwards.
Example:
LeftStr(string, int) v2.07
Returns first int number of characters.
Example:
RightStr(string, int) v2.07
Returns last int number of characters.
Example:
MidStr(string, int pos [, int length]) v2.07
returns substring starting at pos for optional length or to end. Pos=1 specifies start.
Example:
FindStr(string, substring) v2.07
returns position of substring within string. Returns 0 if not found.
Example:
String(float / int) v2
Converts a number to a string.
Example:
Chr(int) v2.51
Returns the ASCII character.
Example:
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).
VersionNumber() v2.07
Returns AviSynth version number as float.
Example:
VersionString() v2.07
Returns AviSynth version info as string (first line used in Version command).
Example:
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 (here a specific call to BicubicResize filter is shown, but you get the idea):
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)
}
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. Return value: Actual MemoryMax value set.
SetPlanarLegacyAlignment (clip, bool): Set alignment mode for planar frames. v2.5.6
Some older plugins illegally assume the layout of video frames in memory. This special filter forces the memory layout of planar frames to be compatible with prior version of AviSynth. The filter works on the GetFrame() call stack, so it effects filters before it in the script.
Example:
# Using an older version of Mpeg2Source()
LoadPlugin("...\Mpeg2Decode.dll")
Mpeg2Source("test.d2v") # A plugin that illegally assumes the layout of memory
SetPlanarLegacyAlignment(true) # Set legacy memory alignment for prior statements
ConvertToYUY2() # Statements thru to the end of the script have
... # advanced memory alignment.
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
Multi threading:
These functions enable avisynth to use more than one thread when processing filters. This is useful if you have more than one cpu/core or hyperthreading. This feature is still experimental.
GetMTMode(bool threads). v.2.6 threads: If true GetMTMode? returns the number of threads used else the current mode is returned (see below). Default value false.
SetMTmode(int mode,int threads). v2.6
Place this at the first line in the avs file to enable temporal (that is more than one frame is processed at the same time) multithreading. Use it later in the script to change the mode for the filters below it.
mode: There are 6 modes 1 to 6. Default value 2.
threads: Number of threads to use. Set to 0 to set it to the number of processors available. It is not possible to change the number of threads other than in the first SetMTMode?. Default value 0.
Example:
SetMTMode(2,0) #enables multihreading using thread = to the number of available processors and mode 2
LoadPlugin("...\LoadPluginEX.dll") #needed to load avisynth 2.0 plugins
LoadPlugin("...\DustV5.dll") #Loads Pixiedust
import("limitedsharpen.avs")
src=AVIsource("test.avi")
SetMTMode(5) #change the mode to 5 for the lines below
src=src.converttoyuy2().PixieDust()#Pixiedust needs mode 5 to function.
SetMTMode(2) #change the mode back to 2
src.LimitedSharpen() #because LimitedSharpen works well with mode 2
subtitle("Number of threads used: "+string(GetMTMode(true))+" Current MT Mode: "+string(GetMTMode())) #display mode and number of threads in use
Conditional Operations:
[var=]boolean expression ? iftrue value or operation : ifelse value or operationnop(): v2.07 null result primarily for if-then-else operation above where ifelse is not desired
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:
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:
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!