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.

281 lines
7.4KB

  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 abs(x)
  18. Compute absolute value of @var{x}.
  19. @item acos(x)
  20. Compute arccosine of @var{x}.
  21. @item asin(x)
  22. Compute arcsine of @var{x}.
  23. @item atan(x)
  24. Compute arctangent of @var{x}.
  25. @item ceil(expr)
  26. Round the value of expression @var{expr} upwards to the nearest
  27. integer. For example, "ceil(1.5)" is "2.0".
  28. @item cos(x)
  29. Compute cosine of @var{x}.
  30. @item cosh(x)
  31. Compute hyperbolic cosine of @var{x}.
  32. @item eq(x, y)
  33. Return 1 if @var{x} and @var{y} are equivalent, 0 otherwise.
  34. @item exp(x)
  35. Compute exponential of @var{x} (with base @code{e}, the Euler's number).
  36. @item floor(expr)
  37. Round the value of expression @var{expr} downwards to the nearest
  38. integer. For example, "floor(-1.5)" is "-2.0".
  39. @item gauss(x)
  40. Compute Gauss function of @var{x}, corresponding to
  41. @code{exp(-x*x/2) / sqrt(2*PI)}.
  42. @item gcd(x, y)
  43. Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
  44. @var{y} are 0 or either or both are less than zero then behavior is undefined.
  45. @item gt(x, y)
  46. Return 1 if @var{x} is greater than @var{y}, 0 otherwise.
  47. @item gte(x, y)
  48. Return 1 if @var{x} is greater than or equal to @var{y}, 0 otherwise.
  49. @item hypot(x, y)
  50. This function is similar to the C function with the same name; it returns
  51. "sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
  52. right triangle with sides of length @var{x} and @var{y}, or the distance of the
  53. point (@var{x}, @var{y}) from the origin.
  54. @item if(x, y)
  55. Evaluate @var{x}, and if the result is non-zero return the result of
  56. the evaluation of @var{y}, return 0 otherwise.
  57. @item if(x, y, z)
  58. Evaluate @var{x}, and if the result is non-zero return the evaluation
  59. result of @var{y}, otherwise the evaluation result of @var{z}.
  60. @item ifnot(x, y)
  61. Evaluate @var{x}, and if the result is zero return the result of the
  62. evaluation of @var{y}, return 0 otherwise.
  63. @item ifnot(x, y, z)
  64. Evaluate @var{x}, and if the result is zero return the evaluation
  65. result of @var{y}, otherwise the evaluation result of @var{z}.
  66. @item isinf(x)
  67. Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise.
  68. @item isnan(x)
  69. Return 1.0 if @var{x} is NAN, 0.0 otherwise.
  70. @item ld(var)
  71. Allow to load the value of the internal variable with number
  72. @var{var}, which was previously stored with st(@var{var}, @var{expr}).
  73. The function returns the loaded value.
  74. @item log(x)
  75. Compute natural logarithm of @var{x}.
  76. @item lt(x, y)
  77. Return 1 if @var{x} is lesser than @var{y}, 0 otherwise.
  78. @item lte(x, y)
  79. Return 1 if @var{x} is lesser than or equal to @var{y}, 0 otherwise.
  80. @item max(x, y)
  81. Return the maximum between @var{x} and @var{y}.
  82. @item min(x, y)
  83. Return the maximum between @var{x} and @var{y}.
  84. @item mod(x, y)
  85. Compute the remainder of division of @var{x} by @var{y}.
  86. @item not(expr)
  87. Return 1.0 if @var{expr} is zero, 0.0 otherwise.
  88. @item pow(x, y)
  89. Compute the power of @var{x} elevated @var{y}, it is equivalent to
  90. "(@var{x})^(@var{y})".
  91. @item random(x)
  92. Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
  93. internal variable which will be used to save the seed/state.
  94. @item root(expr, max)
  95. Find an input value for which the function represented by @var{expr}
  96. with argument @var{ld(0)} is 0 in the interval 0..@var{max}.
  97. The expression in @var{expr} must denote a continuous function or the
  98. result is undefined.
  99. @var{ld(0)} is used to represent the function input value, which means
  100. that the given expression will be evaluated multiple times with
  101. various input values that the expression can access through
  102. @code{ld(0)}. When the expression evaluates to 0 then the
  103. corresponding input value will be returned.
  104. @item sin(x)
  105. Compute sine of @var{x}.
  106. @item sinh(x)
  107. Compute hyperbolic sine of @var{x}.
  108. @item sqrt(expr)
  109. Compute the square root of @var{expr}. This is equivalent to
  110. "(@var{expr})^.5".
  111. @item squish(x)
  112. Compute expression @code{1/(1 + exp(4*x))}.
  113. @item st(var, expr)
  114. Allow to store the value of the expression @var{expr} in an internal
  115. variable. @var{var} specifies the number of the variable where to
  116. store the value, and it is a value ranging from 0 to 9. The function
  117. returns the value stored in the internal variable.
  118. Note, Variables are currently not shared between expressions.
  119. @item tan(x)
  120. Compute tangent of @var{x}.
  121. @item tanh(x)
  122. Compute hyperbolic tangent of @var{x}.
  123. @item taylor(expr, x)
  124. @item taylor(expr, x, id)
  125. Evaluate a Taylor series at @var{x}, given an expression representing
  126. the @code{ld(id)}-th derivative of a function at 0.
  127. When the series does not converge the result is undefined.
  128. @var{ld(id)} is used to represent the derivative order in @var{expr},
  129. which means that the given expression will be evaluated multiple times
  130. with various input values that the expression can access through
  131. @code{ld(id)}. If @var{id} is not specified then 0 is assumed.
  132. Note, when you have the derivatives at y instead of 0,
  133. @code{taylor(expr, x-y)} can be used.
  134. @item time(0)
  135. Return the current (wallclock) time in seconds.
  136. @item trunc(expr)
  137. Round the value of expression @var{expr} towards zero to the nearest
  138. integer. For example, "trunc(-1.5)" is "-1.0".
  139. @item while(cond, expr)
  140. Evaluate expression @var{expr} while the expression @var{cond} is
  141. non-zero, and returns the value of the last @var{expr} evaluation, or
  142. NAN if @var{cond} was always false.
  143. @end table
  144. The following constants are available:
  145. @table @option
  146. @item PI
  147. area of the unit disc, approximately 3.14
  148. @item E
  149. exp(1) (Euler's number), approximately 2.718
  150. @item PHI
  151. golden ratio (1+sqrt(5))/2, approximately 1.618
  152. @end table
  153. Assuming that an expression is considered "true" if it has a non-zero
  154. value, note that:
  155. @code{*} works like AND
  156. @code{+} works like OR
  157. For example the construct:
  158. @example
  159. if (A AND B) then C
  160. @end example
  161. is equivalent to:
  162. @example
  163. if(A*B, C)
  164. @end example
  165. In your C code, you can extend the list of unary and binary functions,
  166. and define recognized constants, so that they are available for your
  167. expressions.
  168. The evaluator also recognizes the International System unit prefixes.
  169. If 'i' is appended after the prefix, binary prefixes are used, which
  170. are based on powers of 1024 instead of powers of 1000.
  171. The 'B' postfix multiplies the value by 8, and can be appended after a
  172. unit prefix or used alone. This allows using for example 'KB', 'MiB',
  173. 'G' and 'B' as number postfix.
  174. The list of available International System prefixes follows, with
  175. indication of the corresponding powers of 10 and of 2.
  176. @table @option
  177. @item y
  178. 10^-24 / 2^-80
  179. @item z
  180. 10^-21 / 2^-70
  181. @item a
  182. 10^-18 / 2^-60
  183. @item f
  184. 10^-15 / 2^-50
  185. @item p
  186. 10^-12 / 2^-40
  187. @item n
  188. 10^-9 / 2^-30
  189. @item u
  190. 10^-6 / 2^-20
  191. @item m
  192. 10^-3 / 2^-10
  193. @item c
  194. 10^-2
  195. @item d
  196. 10^-1
  197. @item h
  198. 10^2
  199. @item k
  200. 10^3 / 2^10
  201. @item K
  202. 10^3 / 2^10
  203. @item M
  204. 10^6 / 2^20
  205. @item G
  206. 10^9 / 2^30
  207. @item T
  208. 10^12 / 2^40
  209. @item P
  210. 10^15 / 2^40
  211. @item E
  212. 10^18 / 2^50
  213. @item Z
  214. 10^21 / 2^60
  215. @item Y
  216. 10^24 / 2^70
  217. @end table
  218. @c man end