Expression Evaluation
*********************

When evaluating an arithmetic expression, FFmpeg uses an internal formula evaluator, implemented through the libavutil/eval.h interface.

An expression may contain unary, binary operators, constants, and functions.

Two expressions EXPR1 and EXPR2 can be combined to form another expression "EXPR1;EXPR2". EXPR1 and EXPR2 are evaluated in turn, and the new expression evaluates to the value of EXPR2.

The following binary operators are available: +, -, *, /, ^.

The following unary operators are available: +, -.

The following functions are available:

sinh(x)

cosh(x)

tanh(x)

sin(x)

cos(x)

tan(x)

atan(x)

asin(x)

acos(x)

exp(x)

log(x)

abs(x)

squish(x)

gauss(x)

isnan(x)
     Return 1.0 if X is NAN, 0.0 otherwise.

mod(x, y)

max(x, y)

min(x, y)

eq(x, y)

gte(x, y)

gt(x, y)

lte(x, y)

lt(x, y)

st(var, expr)
     Allow to store the value of the expression EXPR in an internal variable. VAR specifies the number of the variable where to store the value, and it is a value ranging from 0 to 9. The function returns the value stored in the internal variable. Note, Variables are currently not shared between expressions.

ld(var)
     Allow to load the value of the internal variable with number VAR, which was previously stored with st(VAR, EXPR). The function returns the loaded value.

while(cond, expr)
     Evaluate expression EXPR while the expression COND is non-zero, and returns the value of the last EXPR evaluation, or NAN if COND was always false.

ceil(expr)
     Round the value of expression EXPR upwards to the nearest integer. For example, "ceil(1.5)" is "2.0".

floor(expr)
     Round the value of expression EXPR downwards to the nearest integer. For example, "floor(-1.5)" is "-2.0".

trunc(expr)
     Round the value of expression EXPR towards zero to the nearest integer. For example, "trunc(-1.5)" is "-1.0".

sqrt(expr)
     Compute the square root of EXPR. This is equivalent to "(EXPR)^.5".

not(expr)
     Return 1.0 if EXPR is zero, 0.0 otherwise.

pow(x, y)
     Compute the power of X elevated Y, it is equivalent to "(X)^(Y)".

random(x)
     Return a pseudo random value between 0.0 and 1.0. X is the index of the internal variable which will be used to save the seed/state.

hypot(x, y)
     This function is similar to the C function with the same name; it returns "sqrt(X*X + Y*Y)", the length of the hypotenuse of a right triangle with sides of length X and Y, or the distance of the point (X, Y) from the origin.

gcd(x, y)
     Return the greatest common divisor of X and Y. If both X and Y are 0 or either or both are less than zero then behavior is undefined.

if(x, y)
     Evaluate X, and if the result is non-zero return the result of the evaluation of Y, return 0 otherwise.

ifnot(x, y)
     Evaluate X, and if the result is zero return the result of the evaluation of Y, return 0 otherwise.

The following constants are available:

PI
     area of the unit disc, approximately 3.14

E
     exp(1) (Euler's number), approximately 2.718

PHI
     golden ratio (1+sqrt(5))/2, approximately 1.618

Assuming that an expression is considered "true" if it has a non-zero value, note that:

* works like AND

+ works like OR

and the construct:

     if A then B else C

is equivalent to

     if(A,B) + ifnot(A,C)

In your C code, you can extend the list of unary and binary functions, and define recognized constants, so that they are available for your expressions.

The evaluator also recognizes the International System number postfixes. If 'i' is appended after the postfix, powers of 2 are used instead of powers of 10. The 'B' postfix multiplies the value for 8, and can be appended after another postfix or used alone. This allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.

Follows the list of available International System postfixes, with indication of the corresponding powers of 10 and of 2.

y
     -24 / -80

z
     -21 / -70

a
     -18 / -60

f
     -15 / -50

p
     -12 / -40

n
     -9 / -30

u
     -6 / -20

m
     -3 / -10

c
     -2

d
     -1

h
     2

k
     3 / 10

K
     3 / 10

M
     6 / 20

G
     9 / 30

T
     12 / 40

P
     15 / 40

E
     18 / 50

Z
     21 / 60

Y
     24 / 70