You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.7KB

  1. @chapter Expression Evaluation
  2. @c man begin EXPRESSION EVALUATION
  3. When evaluating an arithmetic expression, FFmpeg uses an internal
  4. formula evaluator, implemented through the @file{libavutil/eval.h}
  5. interface.
  6. An expression may contain unary, binary operators, constants, and
  7. functions.
  8. Two expressions @var{expr1} and @var{expr2} can be combined to form
  9. another expression "@var{expr1};@var{expr2}".
  10. @var{expr1} and @var{expr2} are evaluated in turn, and the new
  11. expression evaluates to the value of @var{expr2}.
  12. The following binary operators are available: @code{+}, @code{-},
  13. @code{*}, @code{/}, @code{^}.
  14. The following unary operators are available: @code{+}, @code{-}.
  15. The following functions are available:
  16. @table @option
  17. @item sinh(x)
  18. @item cosh(x)
  19. @item tanh(x)
  20. @item sin(x)
  21. @item cos(x)
  22. @item tan(x)
  23. @item atan(x)
  24. @item asin(x)
  25. @item acos(x)
  26. @item exp(x)
  27. @item log(x)
  28. @item abs(x)
  29. @item squish(x)
  30. @item gauss(x)
  31. @item isnan(x)
  32. Return 1.0 if @var{x} is NAN, 0.0 otherwise.
  33. @item mod(x, y)
  34. @item max(x, y)
  35. @item min(x, y)
  36. @item eq(x, y)
  37. @item gte(x, y)
  38. @item gt(x, y)
  39. @item lte(x, y)
  40. @item lt(x, y)
  41. @item st(var, expr)
  42. Allow to store the value of the expression @var{expr} in an internal
  43. variable. @var{var} specifies the number of the variable where to
  44. store the value, and it is a value ranging from 0 to 9. The function
  45. returns the value stored in the internal variable.
  46. Note, Variables are currently not shared between expressions.
  47. @item ld(var)
  48. Allow to load the value of the internal variable with number
  49. @var{var}, which was previously stored with st(@var{var}, @var{expr}).
  50. The function returns the loaded value.
  51. @item while(cond, expr)
  52. Evaluate expression @var{expr} while the expression @var{cond} is
  53. non-zero, and returns the value of the last @var{expr} evaluation, or
  54. NAN if @var{cond} was always false.
  55. @item ceil(expr)
  56. Round the value of expression @var{expr} upwards to the nearest
  57. integer. For example, "ceil(1.5)" is "2.0".
  58. @item floor(expr)
  59. Round the value of expression @var{expr} downwards to the nearest
  60. integer. For example, "floor(-1.5)" is "-2.0".
  61. @item trunc(expr)
  62. Round the value of expression @var{expr} towards zero to the nearest
  63. integer. For example, "trunc(-1.5)" is "-1.0".
  64. @item sqrt(expr)
  65. Compute the square root of @var{expr}. This is equivalent to
  66. "(@var{expr})^.5".
  67. @item not(expr)
  68. Return 1.0 if @var{expr} is zero, 0.0 otherwise.
  69. @item pow(x, y)
  70. Compute the power of @var{x} elevated @var{y}, it is equivalent to
  71. "(@var{x})^(@var{y})".
  72. @item random(x)
  73. Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
  74. internal variable which will be used to save the seed/state.
  75. @item hypot(x, y)
  76. This function is similar to the C function with the same name; it returns
  77. "sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
  78. right triangle with sides of length @var{x} and @var{y}, or the distance of the
  79. point (@var{x}, @var{y}) from the origin.
  80. @item gcd(x, y)
  81. Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
  82. @var{y} are 0 or either or both are less than zero then behavior is undefined.
  83. @item if(x, y)
  84. Evaluate @var{x}, and if the result is non-zero return the result of
  85. the evaluation of @var{y}, return 0 otherwise.
  86. @item ifnot(x, y)
  87. Evaluate @var{x}, and if the result is zero return the result of the
  88. evaluation of @var{y}, return 0 otherwise.
  89. @end table
  90. The following constants are available:
  91. @table @option
  92. @item PI
  93. area of the unit disc, approximately 3.14
  94. @item E
  95. exp(1) (Euler's number), approximately 2.718
  96. @item PHI
  97. golden ratio (1+sqrt(5))/2, approximately 1.618
  98. @end table
  99. Assuming that an expression is considered "true" if it has a non-zero
  100. value, note that:
  101. @code{*} works like AND
  102. @code{+} works like OR
  103. and the construct:
  104. @example
  105. if A then B else C
  106. @end example
  107. is equivalent to
  108. @example
  109. if(A,B) + ifnot(A,C)
  110. @end example
  111. In your C code, you can extend the list of unary and binary functions,
  112. and define recognized constants, so that they are available for your
  113. expressions.
  114. The evaluator also recognizes the International System number
  115. postfixes. If 'i' is appended after the postfix, powers of 2 are used
  116. instead of powers of 10. The 'B' postfix multiplies the value for 8,
  117. and can be appended after another postfix or used alone. This allows
  118. using for example 'KB', 'MiB', 'G' and 'B' as postfix.
  119. Follows the list of available International System postfixes, with
  120. indication of the corresponding powers of 10 and of 2.
  121. @table @option
  122. @item y
  123. -24 / -80
  124. @item z
  125. -21 / -70
  126. @item a
  127. -18 / -60
  128. @item f
  129. -15 / -50
  130. @item p
  131. -12 / -40
  132. @item n
  133. -9 / -30
  134. @item u
  135. -6 / -20
  136. @item m
  137. -3 / -10
  138. @item c
  139. -2
  140. @item d
  141. -1
  142. @item h
  143. 2
  144. @item k
  145. 3 / 10
  146. @item K
  147. 3 / 10
  148. @item M
  149. 6 / 20
  150. @item G
  151. 9 / 30
  152. @item T
  153. 12 / 40
  154. @item P
  155. 15 / 40
  156. @item E
  157. 18 / 50
  158. @item Z
  159. 21 / 60
  160. @item Y
  161. 24 / 70
  162. @end table
  163. @c man end