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.

289 lines
7.6KB

  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 print(t)
  92. @item print(t, l)
  93. Print the value of expression @var{t} with loglevel @var{l}. If
  94. @var{l} is not specified then a default log level is used.
  95. Returns the value of the expression printed.
  96. Prints t with loglevel l
  97. @item random(x)
  98. Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
  99. internal variable which will be used to save the seed/state.
  100. @item root(expr, max)
  101. Find an input value for which the function represented by @var{expr}
  102. with argument @var{ld(0)} is 0 in the interval 0..@var{max}.
  103. The expression in @var{expr} must denote a continuous function or the
  104. result is undefined.
  105. @var{ld(0)} is used to represent the function input value, which means
  106. that the given expression will be evaluated multiple times with
  107. various input values that the expression can access through
  108. @code{ld(0)}. When the expression evaluates to 0 then the
  109. corresponding input value will be returned.
  110. @item sin(x)
  111. Compute sine of @var{x}.
  112. @item sinh(x)
  113. Compute hyperbolic sine of @var{x}.
  114. @item sqrt(expr)
  115. Compute the square root of @var{expr}. This is equivalent to
  116. "(@var{expr})^.5".
  117. @item squish(x)
  118. Compute expression @code{1/(1 + exp(4*x))}.
  119. @item st(var, expr)
  120. Allow to store the value of the expression @var{expr} in an internal
  121. variable. @var{var} specifies the number of the variable where to
  122. store the value, and it is a value ranging from 0 to 9. The function
  123. returns the value stored in the internal variable.
  124. Note, Variables are currently not shared between expressions.
  125. @item tan(x)
  126. Compute tangent of @var{x}.
  127. @item tanh(x)
  128. Compute hyperbolic tangent of @var{x}.
  129. @item taylor(expr, x)
  130. @item taylor(expr, x, id)
  131. Evaluate a Taylor series at @var{x}, given an expression representing
  132. the @code{ld(id)}-th derivative of a function at 0.
  133. When the series does not converge the result is undefined.
  134. @var{ld(id)} is used to represent the derivative order in @var{expr},
  135. which means that the given expression will be evaluated multiple times
  136. with various input values that the expression can access through
  137. @code{ld(id)}. If @var{id} is not specified then 0 is assumed.
  138. Note, when you have the derivatives at y instead of 0,
  139. @code{taylor(expr, x-y)} can be used.
  140. @item time(0)
  141. Return the current (wallclock) time in seconds.
  142. @item trunc(expr)
  143. Round the value of expression @var{expr} towards zero to the nearest
  144. integer. For example, "trunc(-1.5)" is "-1.0".
  145. @item while(cond, expr)
  146. Evaluate expression @var{expr} while the expression @var{cond} is
  147. non-zero, and returns the value of the last @var{expr} evaluation, or
  148. NAN if @var{cond} was always false.
  149. @end table
  150. The following constants are available:
  151. @table @option
  152. @item PI
  153. area of the unit disc, approximately 3.14
  154. @item E
  155. exp(1) (Euler's number), approximately 2.718
  156. @item PHI
  157. golden ratio (1+sqrt(5))/2, approximately 1.618
  158. @end table
  159. Assuming that an expression is considered "true" if it has a non-zero
  160. value, note that:
  161. @code{*} works like AND
  162. @code{+} works like OR
  163. For example the construct:
  164. @example
  165. if (A AND B) then C
  166. @end example
  167. is equivalent to:
  168. @example
  169. if(A*B, C)
  170. @end example
  171. In your C code, you can extend the list of unary and binary functions,
  172. and define recognized constants, so that they are available for your
  173. expressions.
  174. The evaluator also recognizes the International System unit prefixes.
  175. If 'i' is appended after the prefix, binary prefixes are used, which
  176. are based on powers of 1024 instead of powers of 1000.
  177. The 'B' postfix multiplies the value by 8, and can be appended after a
  178. unit prefix or used alone. This allows using for example 'KB', 'MiB',
  179. 'G' and 'B' as number postfix.
  180. The list of available International System prefixes follows, with
  181. indication of the corresponding powers of 10 and of 2.
  182. @table @option
  183. @item y
  184. 10^-24 / 2^-80
  185. @item z
  186. 10^-21 / 2^-70
  187. @item a
  188. 10^-18 / 2^-60
  189. @item f
  190. 10^-15 / 2^-50
  191. @item p
  192. 10^-12 / 2^-40
  193. @item n
  194. 10^-9 / 2^-30
  195. @item u
  196. 10^-6 / 2^-20
  197. @item m
  198. 10^-3 / 2^-10
  199. @item c
  200. 10^-2
  201. @item d
  202. 10^-1
  203. @item h
  204. 10^2
  205. @item k
  206. 10^3 / 2^10
  207. @item K
  208. 10^3 / 2^10
  209. @item M
  210. 10^6 / 2^20
  211. @item G
  212. 10^9 / 2^30
  213. @item T
  214. 10^12 / 2^40
  215. @item P
  216. 10^15 / 2^40
  217. @item E
  218. 10^18 / 2^50
  219. @item Z
  220. 10^21 / 2^60
  221. @item Y
  222. 10^24 / 2^70
  223. @end table
  224. @c man end