<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on April 27, 2012 by texi2html 1.82
texi2html was written by: 
            Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>Untitled Document</title>

<meta name="description" content="Untitled Document">
<meta name="keywords" content="Untitled Document">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Expression-Evaluation"></a>
<h1 class="chapter">1. Expression Evaluation</h1>

<p>When evaluating an arithemetic expression, FFmpeg uses an internal
formula evaluator, implemented through the &lsquo;<tt>libavutil/eval.h</tt>&rsquo;
interface.
</p>
<p>An expression may contain unary, binary operators, constants, and
functions.
</p>
<p>Two expressions <var>expr1</var> and <var>expr2</var> can be combined to form
another expression &quot;<var>expr1</var>;<var>expr2</var>&quot;.
<var>expr1</var> and <var>expr2</var> are evaluated in turn, and the new
expression evaluates to the value of <var>expr2</var>.
</p>
<p>The following binary operators are available: <code>+</code>, <code>-</code>,
<code>*</code>, <code>/</code>, <code>^</code>.
</p>
<p>The following unary operators are available: <code>+</code>, <code>-</code>.
</p>
<p>The following functions are available:
</p><dl compact="compact">
<dt> &lsquo;<samp>sinh(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>cosh(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>tanh(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>sin(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>cos(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>tan(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>atan(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>asin(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>acos(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>exp(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>log(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>abs(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>squish(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>gauss(x)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>isnan(x)</samp>&rsquo;</dt>
<dd><p>Return 1.0 if <var>x</var> is NAN, 0.0 otherwise.
</p>
</dd>
<dt> &lsquo;<samp>mod(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>max(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>min(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>eq(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>gte(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>gt(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>lte(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>lt(x, y)</samp>&rsquo;</dt>
<dt> &lsquo;<samp>st(var, expr)</samp>&rsquo;</dt>
<dd><p>Allow to store the value of the expression <var>expr</var> in an internal
variable. <var>var</var> specifies the number of the variable where to
store the value, and it is a value ranging from 0 to 9. The function
returns the value stored in the internal variable.
</p>
</dd>
<dt> &lsquo;<samp>ld(var)</samp>&rsquo;</dt>
<dd><p>Allow to load the value of the internal variable with number
<var>var</var>, which was previosly stored with st(<var>var</var>, <var>expr</var>).
The function returns the loaded value.
</p>
</dd>
<dt> &lsquo;<samp>while(cond, expr)</samp>&rsquo;</dt>
<dd><p>Evaluate expression <var>expr</var> while the expression <var>cond</var> is
non-zero, and returns the value of the last <var>expr</var> evaluation, or
NAN if <var>cond</var> was always false.
</p></dd>
</dl>

<p>Note that:
</p>
<p><code>*</code> works like AND
</p>
<p><code>+</code> works like OR
</p>
<p>thus
</p><table><tr><td>&nbsp;</td><td><pre class="example">if A then B else C
</pre></td></tr></table>
<p>is equivalent to
</p><table><tr><td>&nbsp;</td><td><pre class="example">A*B + not(A)*C
</pre></td></tr></table>

<p>When A evaluates to either 1 or 0, that is the same as
</p><table><tr><td>&nbsp;</td><td><pre class="example">A*B + eq(A,0)*C
</pre></td></tr></table>

<p>In your C code, you can extend the list of unary and binary functions,
and define recognized constants, so that they are available for your
expressions.
</p>
<p>The evaluator also recognizes the International System number
postfixes. If &rsquo;i&rsquo; is appended after the postfix, powers of 2 are used
instead of powers of 10. The &rsquo;B&rsquo; postfix multiplies the value for 8,
and can be appended after another postfix or used alone. This allows
using for example &rsquo;KB&rsquo;, &rsquo;MiB&rsquo;, &rsquo;G&rsquo; and &rsquo;B&rsquo; as postfix.
</p>
<p>Follows the list of available International System postfixes, with
indication of the corresponding powers of 10 and of 2.
</p><dl compact="compact">
<dt> &lsquo;<samp>y</samp>&rsquo;</dt>
<dd><p>-24 / -80
</p></dd>
<dt> &lsquo;<samp>z</samp>&rsquo;</dt>
<dd><p>-21 / -70
</p></dd>
<dt> &lsquo;<samp>a</samp>&rsquo;</dt>
<dd><p>-18 / -60
</p></dd>
<dt> &lsquo;<samp>f</samp>&rsquo;</dt>
<dd><p>-15 / -50
</p></dd>
<dt> &lsquo;<samp>p</samp>&rsquo;</dt>
<dd><p>-12 / -40
</p></dd>
<dt> &lsquo;<samp>n</samp>&rsquo;</dt>
<dd><p>-9 / -30
</p></dd>
<dt> &lsquo;<samp>u</samp>&rsquo;</dt>
<dd><p>-6 / -20
</p></dd>
<dt> &lsquo;<samp>m</samp>&rsquo;</dt>
<dd><p>-3 / -10
</p></dd>
<dt> &lsquo;<samp>c</samp>&rsquo;</dt>
<dd><p>-2
</p></dd>
<dt> &lsquo;<samp>d</samp>&rsquo;</dt>
<dd><p>-1
</p></dd>
<dt> &lsquo;<samp>h</samp>&rsquo;</dt>
<dd><p>2
</p></dd>
<dt> &lsquo;<samp>k</samp>&rsquo;</dt>
<dd><p>3 / 10
</p></dd>
<dt> &lsquo;<samp>K</samp>&rsquo;</dt>
<dd><p>3 / 10
</p></dd>
<dt> &lsquo;<samp>M</samp>&rsquo;</dt>
<dd><p>6 / 20
</p></dd>
<dt> &lsquo;<samp>G</samp>&rsquo;</dt>
<dd><p>9 / 30
</p></dd>
<dt> &lsquo;<samp>T</samp>&rsquo;</dt>
<dd><p>12 / 40
</p></dd>
<dt> &lsquo;<samp>P</samp>&rsquo;</dt>
<dd><p>15 / 40
</p></dd>
<dt> &lsquo;<samp>E</samp>&rsquo;</dt>
<dd><p>18 / 50
</p></dd>
<dt> &lsquo;<samp>Z</samp>&rsquo;</dt>
<dd><p>21 / 60
</p></dd>
<dt> &lsquo;<samp>Y</samp>&rsquo;</dt>
<dd><p>24 / 70
</p></dd>
</dl>

<hr size="1">
<p>
 <font size="-1">
  This document was generated by <em>Christopher Martin</em> on <em>April 27, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
 </font>
 <br>

</p>
</body>
</html>
