ScriptFunctions のバックアップソース(No.9)

*スクリプト関数: [#iea63ce3]

これらの関数の入出力は、クリップではなく、スクリプトの中で使われる別の変数です。

#contents

**数値関数: [#u1ee7bc9]

#hr

 Floor(float)

floatからintへ変換します(小数点以下の端数を切り捨て)。

''例:''

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

#hr

 Ceil(float)

floatからintへ変換します(小数点以下の端数を切り上げ)。

''例:''

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

#hr

 Round(float)

floatからintへ変換します(最も近い整数に四捨五入する)。

''例:''

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

#hr

 Sin(float) v2

#hr

 Cos(float) v2

#hr

 Pi() v2

#hr

 Log(float) v2

#hr

 Exp(float) v2

#hr

 Pow(float base, float power) v2

#hr

 Sqrt(float) v2

#hr

 Abs(float or integer) v2.07

絶対値を返します(floatにはfloatを、整数には整数を返す)。

''例:''

 Abs(-3.8) = 3.8 

#hr

 Sign(float) v2.07

値の符号を返します(1、0、または-1)。

''例:''

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

#hr

 Int(float) v2.07

floatからintへ変換します(0のほうへ丸める)。

''例:''

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

#hr

 Frac(float) v2.07

与えられた値の小数点以下の端数分を返します。

''例:''

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

#hr

 Float(int) v2.07

intをfloatへ変換します。

#hr

 Value(string) v2.07

文字列を数値へ変換します。

#hr

 HexValue(string) v2.07

文字列を16進数の値として評価します。

''例:''

 HexValue ("FF00") = 65280

#hr

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

ランダムな整数値を返します。すべてのパラメータはオプションです。maxは最大値+1を設定し(デフォルト 32768)、負の結果のために負の値を設定することができます。scaledモードかmodulus((訳者註: 係数の意。)モードのどちらかで処理します(デフォルトは、maxの絶対値が32768より大きいならscale=true、それ以外はscale=false)。scaledモードは、内部のランダム数ジェネレータの値を最大値(max)にあわせて調整します。一方、modulusモード(scale=false)は、整数の割り算により、最大値でランダムジェネレータの値を割ったときの余りを使用します。最大値が小さいときほど、modulusモードが最適です。seed=trueを使うと、ランダム数ジェネレータに現在の時間をシード(seed)します。デフォルトではfalseとなり、おそらくseed=trueを使用する必要はありません。しかし、万一に備えて、seedパラメータは存在します。一般的に、この関数は、ランダムなクリップ用のSelect関数と一緒に使用されます。

''例:''

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

#hr

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

コントロールポイント(制御点)x1/y1などを使って、Yの値をX点で補間します。x/yのペアは、少なくとも2つ以上でなければなりません。補間は、3次(cubic)補間(結果はスプライン)か線形(linear)補間(結果は多角形(polygon))になります。

''例:''

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

#hr

**文字列関数: [#s1b75b61]

#hr

 LCase(string) v2.07

stringを小文字で返します。

''例:''

 LCase("AviSynth") = "avisynth" 

#hr

 UCase(string) v2.07

stringを大文字で返します。

''例:''

 UCase("AviSynth") = "AVISYNTH" 

#hr

 StrLen(string) v2.07

stringの長さを返します。

''例:''

 StrLen("AviSynth") = 8 

#hr

 RevStr(string) v2.07

stringを逆さまに返します。

''例:''

 RevStr("AviSynth") = "htnySivA" 

#hr

 LeftStr(string, int) v2.07

文字列の最初のint個を返します。

''例:''

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

#hr

 RightStr(string, int) v2.07

文字列の最後のint個を返します。

''例:''

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

#hr

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

pos番目の文字から、オプションで指定するlength個分、またはstringの最後までのサブストリング(部分文字列)を返します。pos=1は、stringの先頭を明示します。

''例:''

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

#hr

 FindStr(string, substring) v2.07

stirngの中におけるsubstringのポジションを返します。見つからないなら、0を返します。

''例:''

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

#hr

 String(float / int) v2

数字をstringに変換します。

''例:''

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

#hr

 Chr(int) v2.51

アスキー文字を返します。


''例:''

 Chr(34) # 引用文字を返します。

#hr

 Time(string) v2.51

stringによって定義されたフォーマットで、現在のシステム時間に関するstringを返します。出力フォーマットのためのコード:

%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).

#hr

**バージョンチェック関数: [#k3d35a2c]

#hr

 VersionNumber() v2.07

AviSynthのバージョンナンバーをfloatとして返します。

''例:''

 VersionNumber() = 2.07 

#hr

 VersionString() v2.07

AviSynthのバージョン情報をstringとして返します(Versionフィルタで使用される最初の行)。

''例:''

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

#hr

**変数型およびファイルをチェックする関数: [#sb873dca]

 IsBool(var)

 IsInt(var)

 IsFloat(var)

 IsString(var)

 IsClip(var)

 Exist(filename) v2.07

明記されたファイルが存在するかどうかをチェックします。

 Defined(var)

: varが定義されているならtrueを、さもなければfalseを返します。

 Default(x,d)

: Defined(x)ならxを、さもなければdを返します。

註: DefinedとDefaultは、主として、ユーザー定義関数においてオプションで宣言される変数を扱うことを目的として作られており、オプションの変数が渡されているかどうかを決定するために使われます。完全に宣言されていない変数は、エラーを生成するでしょう。より詳しい情報に関しては、このセクションの"[[ユーザー定義関数>#user_defined_functions]]"を、後で見てください。

 Eval(string)

 Apply(func-string, arg, ...)

: Eval("f(x)")は、Apply("f", x))に相当します。

'''Evalは、以下のように使うことができます:'''

 settings = "352, 288"
 
 Eval( "BicubicResize(" + settings + ")" )

'''別のスクリプトのテキストをインポートすることができます:'''

 Import (filename)

: 別のAviSynthスクリプトの内容を評価(eval)します。

'''エラーリポートとユーザー定義関数への不正な入力をキャッチするために、以下の関数を使うことができます(bool=falseなら、error-message):'''

 Assert (bool, string error-message)

エラーが発生する''であろう''かどうかをチェックするための関数があります:

 Try {
 
 AviSource("file.avi")
 }
 
 catch(err_msg) {
 
 Blackness.Subtitle(err_msg)
 
 }

**Control Functions: [#u1280d7c]

 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.

''&aname(user_defined_functions);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