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.

207 lines
5.2KB

  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 isinf(x)
  32. Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise.
  33. @item isnan(x)
  34. Return 1.0 if @var{x} is NAN, 0.0 otherwise.
  35. @item mod(x, y)
  36. @item max(x, y)
  37. @item min(x, y)
  38. @item eq(x, y)
  39. @item gte(x, y)
  40. @item gt(x, y)
  41. @item lte(x, y)
  42. @item lt(x, y)
  43. @item st(var, expr)
  44. Allow to store the value of the expression @var{expr} in an internal
  45. variable. @var{var} specifies the number of the variable where to
  46. store the value, and it is a value ranging from 0 to 9. The function
  47. returns the value stored in the internal variable.
  48. Note, Variables are currently not shared between expressions.
  49. @item ld(var)
  50. Allow to load the value of the internal variable with number
  51. @var{var}, which was previously stored with st(@var{var}, @var{expr}).
  52. The function returns the loaded value.
  53. @item while(cond, expr)
  54. Evaluate expression @var{expr} while the expression @var{cond} is
  55. non-zero, and returns the value of the last @var{expr} evaluation, or
  56. NAN if @var{cond} was always false.
  57. @item ceil(expr)
  58. Round the value of expression @var{expr} upwards to the nearest
  59. integer. For example, "ceil(1.5)" is "2.0".
  60. @item floor(expr)
  61. Round the value of expression @var{expr} downwards to the nearest
  62. integer. For example, "floor(-1.5)" is "-2.0".
  63. @item trunc(expr)
  64. Round the value of expression @var{expr} towards zero to the nearest
  65. integer. For example, "trunc(-1.5)" is "-1.0".
  66. @item sqrt(expr)
  67. Compute the square root of @var{expr}. This is equivalent to
  68. "(@var{expr})^.5".
  69. @item not(expr)
  70. Return 1.0 if @var{expr} is zero, 0.0 otherwise.
  71. @item pow(x, y)
  72. Compute the power of @var{x} elevated @var{y}, it is equivalent to
  73. "(@var{x})^(@var{y})".
  74. @item random(x)
  75. Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
  76. internal variable which will be used to save the seed/state.
  77. @item hypot(x, y)
  78. This function is similar to the C function with the same name; it returns
  79. "sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
  80. right triangle with sides of length @var{x} and @var{y}, or the distance of the
  81. point (@var{x}, @var{y}) from the origin.
  82. @item gcd(x, y)
  83. Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
  84. @var{y} are 0 or either or both are less than zero then behavior is undefined.
  85. @item if(x, y)
  86. Evaluate @var{x}, and if the result is non-zero return the result of
  87. the evaluation of @var{y}, return 0 otherwise.
  88. @item ifnot(x, y)
  89. Evaluate @var{x}, and if the result is zero return the result of the
  90. evaluation of @var{y}, return 0 otherwise.
  91. @item taylor(expr, x) taylor(expr, x, id)
  92. Evaluate a taylor series at x.
  93. expr represents the LD(id)-th derivates of f(x) at 0. If id is not specified
  94. then 0 is assumed.
  95. note, when you have the derivatives at y instead of 0
  96. taylor(expr, x-y) can be used
  97. When the series does not converge the results are undefined.
  98. @item root(expr, max)
  99. Finds x where f(x)=0 in the interval 0..max.
  100. f() must be continuous or the result is undefined.
  101. @end table
  102. The following constants are available:
  103. @table @option
  104. @item PI
  105. area of the unit disc, approximately 3.14
  106. @item E
  107. exp(1) (Euler's number), approximately 2.718
  108. @item PHI
  109. golden ratio (1+sqrt(5))/2, approximately 1.618
  110. @end table
  111. Assuming that an expression is considered "true" if it has a non-zero
  112. value, note that:
  113. @code{*} works like AND
  114. @code{+} works like OR
  115. and the construct:
  116. @example
  117. if A then B else C
  118. @end example
  119. is equivalent to
  120. @example
  121. if(A,B) + ifnot(A,C)
  122. @end example
  123. In your C code, you can extend the list of unary and binary functions,
  124. and define recognized constants, so that they are available for your
  125. expressions.
  126. The evaluator also recognizes the International System number
  127. postfixes. If 'i' is appended after the postfix, powers of 2 are used
  128. instead of powers of 10. The 'B' postfix multiplies the value for 8,
  129. and can be appended after another postfix or used alone. This allows
  130. using for example 'KB', 'MiB', 'G' and 'B' as postfix.
  131. Follows the list of available International System postfixes, with
  132. indication of the corresponding powers of 10 and of 2.
  133. @table @option
  134. @item y
  135. -24 / -80
  136. @item z
  137. -21 / -70
  138. @item a
  139. -18 / -60
  140. @item f
  141. -15 / -50
  142. @item p
  143. -12 / -40
  144. @item n
  145. -9 / -30
  146. @item u
  147. -6 / -20
  148. @item m
  149. -3 / -10
  150. @item c
  151. -2
  152. @item d
  153. -1
  154. @item h
  155. 2
  156. @item k
  157. 3 / 10
  158. @item K
  159. 3 / 10
  160. @item M
  161. 6 / 20
  162. @item G
  163. 9 / 30
  164. @item T
  165. 12 / 40
  166. @item P
  167. 15 / 40
  168. @item E
  169. 18 / 50
  170. @item Z
  171. 21 / 60
  172. @item Y
  173. 24 / 70
  174. @end table
  175. @c man end