## ffmpeg / doc / eval.texi @ 512f973e

History | View | Annotate | Download (2.92 KB)

1 |
@chapter Expression Evaluation |
---|---|

2 |
@c man begin EXPRESSION EVALUATION |

3 | |

4 |
When evaluating an arithemetic expression, FFmpeg uses an internal |

5 |
formula evaluator, implemented through the @file{libavutil/eval.h} |

6 |
interface. |

7 | |

8 |
An expression may contain unary, binary operators, constants, and |

9 |
functions. |

10 | |

11 |
Two expressions @var{expr1} and @var{expr2} can be combined to form |

12 |
another expression "@var{expr1};@var{expr2}". |

13 |
@var{expr1} and @var{expr2} are evaluated in turn, and the new |

14 |
expression evaluates to the value of @var{expr2}. |

15 | |

16 |
The following binary operators are available: @code{+}, @code{-}, |

17 |
@code{*}, @code{/}, @code{^}. |

18 | |

19 |
The following unary operators are available: @code{+}, @code{-}. |

20 | |

21 |
The following functions are available: |

22 |
@table @option |

23 |
@item sinh(x) |

24 |
@item cosh(x) |

25 |
@item tanh(x) |

26 |
@item sin(x) |

27 |
@item cos(x) |

28 |
@item tan(x) |

29 |
@item atan(x) |

30 |
@item asin(x) |

31 |
@item acos(x) |

32 |
@item exp(x) |

33 |
@item log(x) |

34 |
@item abs(x) |

35 |
@item squish(x) |

36 |
@item gauss(x) |

37 |
@item isnan(x) |

38 |
Return 1.0 if @var{x} is NAN, 0.0 otherwise. |

39 | |

40 |
@item mod(x, y) |

41 |
@item max(x, y) |

42 |
@item min(x, y) |

43 |
@item eq(x, y) |

44 |
@item gte(x, y) |

45 |
@item gt(x, y) |

46 |
@item lte(x, y) |

47 |
@item lt(x, y) |

48 |
@item st(var, expr) |

49 |
Allow to store the value of the expression @var{expr} in an internal |

50 |
variable. @var{var} specifies the number of the variable where to |

51 |
store the value, and it is a value ranging from 0 to 9. The function |

52 |
returns the value stored in the internal variable. |

53 | |

54 |
@item ld(var) |

55 |
Allow to load the value of the internal variable with number |

56 |
@var{var}, which was previosly stored with st(@var{var}, @var{expr}). |

57 |
The function returns the loaded value. |

58 | |

59 |
@item while(cond, expr) |

60 |
Evaluate expression @var{expr} while the expression @var{cond} is |

61 |
non-zero, and returns the value of the last @var{expr} evaluation, or |

62 |
NAN if @var{cond} was always false. |

63 |
@end table |

64 | |

65 |
Note that: |

66 | |

67 |
@code{*} works like AND |

68 | |

69 |
@code{+} works like OR |

70 | |

71 |
thus |

72 |
@example |

73 |
if A then B else C |

74 |
@end example |

75 |
is equivalent to |

76 |
@example |

77 |
A*B + not(A)*C |

78 |
@end example |

79 | |

80 |
When A evaluates to either 1 or 0, that is the same as |

81 |
@example |

82 |
A*B + eq(A,0)*C |

83 |
@end example |

84 | |

85 |
In your C code, you can extend the list of unary and binary functions, |

86 |
and define recognized constants, so that they are available for your |

87 |
expressions. |

88 | |

89 |
The evaluator also recognizes the International System number |

90 |
postfixes. If 'i' is appended after the postfix, powers of 2 are used |

91 |
instead of powers of 10. The 'B' postfix multiplies the value for 8, |

92 |
and can be appended after another postfix or used alone. This allows |

93 |
using for example 'KB', 'MiB', 'G' and 'B' as postfix. |

94 | |

95 |
Follows the list of available International System postfixes, with |

96 |
indication of the corresponding powers of 10 and of 2. |

97 |
@table @option |

98 |
@item y |

99 |
-24 / -80 |

100 |
@item z |

101 |
-21 / -70 |

102 |
@item a |

103 |
-18 / -60 |

104 |
@item f |

105 |
-15 / -50 |

106 |
@item p |

107 |
-12 / -40 |

108 |
@item n |

109 |
-9 / -30 |

110 |
@item u |

111 |
-6 / -20 |

112 |
@item m |

113 |
-3 / -10 |

114 |
@item c |

115 |
-2 |

116 |
@item d |

117 |
-1 |

118 |
@item h |

119 |
2 |

120 |
@item k |

121 |
3 / 10 |

122 |
@item K |

123 |
3 / 10 |

124 |
@item M |

125 |
6 / 20 |

126 |
@item G |

127 |
9 / 30 |

128 |
@item T |

129 |
12 / 40 |

130 |
@item P |

131 |
15 / 40 |

132 |
@item E |

133 |
18 / 50 |

134 |
@item Z |

135 |
21 / 60 |

136 |
@item Y |

137 |
24 / 70 |

138 |
@end table |

139 | |

140 |
@c man end |