User:Raffriff42/sandbox
From Avisynth wiki
(Non-clip_functions work in progress)
Boolean functions
- They return true or false, if the condition that they test holds or not, respectively.
IsBool | | IsBool(var)
- Tests if var is of the bool type. var can be any expression allowed by the AviSynth Syntax.
- Examples:
b = false IsBool(b) = true IsBool(1 < 2 && 0 == 1) = true IsBool(123) = false
IsClip | | IsClip(var)
- Tests if var is of the clip type. var can be any expression allowed by the AviSynth Syntax.
- Examples:
c = AviSource(...) IsClip(c) = true IsClip("c") = false
IsFloat | | IsFloat(var)
- Tests if var is of the float type. var can be any expression allowed by the AviSynth Syntax.
- Examples:
f = Sqrt(2) IsFloat(f) = true IsFloat(2) = true # ints are considered to be floats by this function IsFloat(true) = false
IsInt | | IsInt(var)
- Tests if var is of the int type. var can be any expression allowed by the AviSynth Syntax.
- Examples:
IsInt(2) = true IsInt(2.1) = false IsInt(true) = false
IsString | | IsString(var)
- Tests if var is of the string type. var can be any expression allowed by the AviSynth Syntax.
- Examples:
IsString("test") = true IsString(2.3) = false IsString(String(2.3)) = true
Exist | v2.07 | Exist(filename)
- Tests if the file specified by filename exists.
- Examples:
filename = ... clp = Exist(filename) ? AviSource(filename) : Assert(false, "file: " + filename + " does not exist")
Defined | | Defined(var)
- Tests if var is defined. Can be used inside Script_functions to test if an optional argument has been given an explicit value.
- More formally, the function returns false if its argument (normally a function argument or variable) has the void ('undefined') type, otherwise it returns true.
- Examples:
b_arg_supplied = Defined(arg) myvar = b_arg_supplied ? ... : ...
Control functions
- They facilitate flow of control (loading of scripts, arguments checks, global settings adjustment, etc.).
Apply | | Apply(string func_string [, arg1 [, arg2 [, ... [, argn]]]] )
- Apply calls the function or filter func_string with arguments arg1, arg2, ..., argn (as many as supplied). Thus, it provides a way to call a function or filter by name providing arguments in the usual way as in a typical function call.
- Consequently, Apply("f", x) is equivalent to f(x) which in turn is equivalent to Eval("f(" + String(x) + ")").
- Examples:
# here the same call to BicubicResize as in the Eval() example is shown Apply("BicubicResize", last, 352, 288) # Note that the clip argument must be supplied - 'last' is not implicitly assumed
Eval | | Eval(expression [, string name])
- Eval evaluates an arbitrary expression as if it was placed inside the script at the point of the call to Eval and returns the result of evaluation (either to the variable that is explicitly assigned to or to the last special variable.
- You can use Eval to construct and evaluate expressions dynamically inside your scripts, based on variable input data. Below some specific examples are shown but you get the general idea.
- Argument name will be shown in the error message besides the script name. Both will be followed with the line number in the script where the is error caused.
- Examples:
# this calls BicubicResize(last, 352, 288) settings = "352, 288" Eval( "BicubicResize(" + settings + ")" ) ... # this will result in Defined(u) == false u = Eval("#") ... # this increments a global based on a variable's value dummy = Eval("global my_counter = my_counter + " + String(increment))
Import | | Import(filename)
- Import evaluates the contents of another AviSynth script and returns the imported script's return value. Typically it is used to make available to the calling script library functions and the return value is not used. However this is simply a convention; it is not enforced by the AviSynth Syntax. See also the dedicated Import page in Internal filters for other possible uses.
- Possible scenarios (an indicative list) where the return value could be of use is for the library script to:
- indicate whether it succesfully initialised itself (a bool return value),
- inform for the number of presets found on disk (an int return value);
- the value then could be tested by the calling script to decide what action to take next.
- Examples:
Import("mylib.avsi") # here we do not care about the value (mylib.avsi contains only functions) ... okflag = Import("mysources.avsi") # mysources loads predetermined filenames from a folder into globals source = okflag ? global1 + global2 + global3 : BlankClip()
Select | | Select(index, item0 [, item1 [, ...[, itemn]]])
- Returns the item selected by the index argument, which must be of int type (0 returns item0, 1 returns item1, ..., etc). Items can be any script variable or expression of any type and can even be mixed.
- Examples:
# select a clip-brush from a set of presets idx = 2 brush = Select(idx, AviSource("round.avi"), rectangle, diagonal, diagonal.FlipHorizontal)
Default | | Default(x, d)
- Returns x if Defined(x) is true, d otherwise. x must either be a function's argument or an already declared script variable (ie a variable which has been assigned a value) else an error will occur.
- Examples:
function myfunc(clip c, ..., int "strength") { ... strength = Default(strength, 4) # if not supplied make it 4 ... }
Assert | | Assert(condition [, err_msg])
- Does nothing if condition is true; throws an error, immediately terminating script execution, if condition is false. In the later case err_msg, if supplied, is presented to the user through a dialog box; else the standard message "Assert: assertion failed". shows up.
- Examples:
function myfunc(clip c, ..., int "strength") { ... strength = Default(strength, 4) # if not supplied make it 4 Assert(strength > 0, "'strength' must be positive") ... }
NOP | | NOP()
- This is a no-operation function provided mainly for conditional execution with non-return value items such as Import, when no "else" condition is desired. That is, use it whenever the AviSynth Syntax requires an operation (such as with the ?: operator) but your script does not need one.
- Return value: 0 (int type).
- Examples:
preset = want_presets ? AviSource("c:\presets\any.avi") : NOP ... loadlib ? Import("my_useful_functions.avs") : NOP
UnDefined | v2.60 | UnDefined()
- Returns the undefined state.
- It's the state for which Defined() returns false.
- Examples:
x = Undefined() Defined(x) # = true
SetMemoryMax | v2 | SetMemoryMax(amount)
- Sets the maximum memory that AviSynth uses (in MB) to the value of amount. Setting to zero just returns the current Memory Max value. v2, (=0) v2.58. In the 2.5 series the default Memory Max value is 25% of the free physical memory, with a minimum of 16MB.
- From v2.58, the default Memory Max is also limited to 512MB.
Free memory <64 128 256 512 1024 2048 3072 Max v2.57 and older 16 32 64 128 256 512 768 Default Max since v2.58 16 32 64 192 448 512 512
- 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. Too high values can result in crashes because of 2GB address space limit.
- Return value: Actual MemoryMax value set.
- Examples:
SetMemoryMax(128)
SetWorkingDir | v2 | SetWorkingDir(path)
- Sets the default directory for AviSynth to the path argument.
- This is primarily for easy loading of source clips, importing scripts, etc. It does not affect plugins' autoloading.
- Return value is 0 if successful, -1 otherwise.
- Examples:
SetWorkingDir("c:\my_presets") AviSource("border_mask.avi") # this loads c:\my_presets\border_mask.avi
SetPlanarLegacyAlignment | v2.56 | SetPlanarLegacyAlignment(mode)
- Set alignment mode for planar frames. mode can either be true or false.
- 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 versions of AviSynth. The filter works on the GetFrame() call stack, so it effects filters before it in the script.
- Examples:
Example : Using an older version of Mpeg2Source() (1.10 or older): 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 through to the end of the script have ... # advanced memory alignment.
OPT_AllowFloatAudio | v2.57 | global OPT_AllowFloatAudio = True
- This option enables WAVE_FORMAT_IEEE_FLOAT audio output. The default is to autoconvert Float audio to 16 bit.
OPT_UseWaveExtensible | v2.58 | global OPT_UseWaveExtensible = True
- This option enables WAVE_FORMAT_EXTENSIBLE audio output. The default is WAVE_FORMAT_EX.
- Note: The default DirectShow component for .AVS files, "AVI/WAV File Source", does not correctly implement WAVE_FORMAT_EXTENSIBLE processing, so many application may not be able to detect the audio track. There are third party DirectShow readers that do work correctly. Intermediate work files written using the AVIFile interface for later DirectShow processing will work correctly if they use the DirectShow "File Source (async)" component or equivalent.
OPT_VDubPlanarHack | v2.60 | global OPT_VDubPlanarHack = True
- This option enables flipped YV24 and YV16 chroma planes. This is an hack for early versions of Virtualdub with YV24/YV16 support.
OPT_dwChannelMask | v2.60 | global OPT_dwChannelMask(int v)
- This option enables you to set ChannelMask. It overrides WAVEFORMATEXTENSIBLE.dwChannelMask which is set according to this table
- 0x00004, // 1 -- -- Cf
- 0x00003, // 2 Lf Rf
- 0x00007, // 3 Lf Rf Cf
- 0x00033, // 4 Lf Rf -- -- Lr Rr
- 0x00037, // 5 Lf Rf Cf -- Lr Rr
- 0x0003F, // 5.1 Lf Rf Cf Sw Lr Rr
- 0x0013F, // 6.1 Lf Rf Cf Sw Lr Rr -- -- Cr
- 0x0063F, // 7.1 Lf Rf Cf Sw Lr Rr -- -- -- Ls Rs
OPT_AVIPadScanlines | v2.60 | global OPT_AVIPadScanlines = True
- This option enables DWORD aligned planar padding. Default is packed aligned planar padding. See memory alignment used in the AVIFile output emulation.
Conversion functions
- These convert between different types.
Numeric functions
- They provide common mathematical operations on numeric variables.
Value | v2.07 | Value(string)
- Converts a decimal string to its associated numeric value.
- Examples:
Value ("-2.7") = -2.7
HexValue | v2.07 | HexValue(string)
- Converts a hexadecimal string to its associated numeric value.
- Examples:
HexValue ("FF00") = 65280
Hex | v2.60 | Hex(int)
- Converts a numerical value to its hexadecimal value. See Colors for more information on specifying colors.
- Examples:
Hex (10824234) = "A52A2A"
String | v2.07 | String(float / int [, string format_string])
- Converts a variable to a string.
- If the variable is float or integer, it first converts it to a float and then uses format_string to convert the float to a string. The syntax of format_string is as follows:
- %[flags][width][.precision]f
- flags:
- - left align (instead right align)
- + always print the +/- sign
- 0 padding with leading zeros
- ' ' print a blank instead of a "+"
- # always print the decimal point
- width: the minimum width (the string is never truncated)
- precision: the number of digits printed
- You can also put arbitrary text around the format_string as defined above, similar to the C-language printf function.
- Examples:
Subtitle( "Clip height is " + String(last.height) ) Subtitle( String(x, "Value of x is %.3f after AR calc") ) Subtitle( "Value of x is " + String(x, "%.3f") + " after AR calc") ) # same as above String(1.23, "%f") = '1.23' String(1.23, "%5.1f") = ' 1.2' String(1.23, "%1.3f") = '1.230' String(24, "%05.0f") = '00024'
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
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.
Runtime functions
- These are internal functions which are evaluated at every frame. They can be used inside the scripts passed to runtime filters (ConditionalFilter, ScriptClip, FrameEvaluate) to return information for a frame.
Script functions
- They provide AviSynth script information.
String functions
- They provide common operations on string variables.
Version functions
- They provide AviSynth version information.
Back to AviSynth Syntax.