[FFmpeg-devel] [PATCH] lavu/eval: add ifzero() and ifnonzero() expression

Stefano Sabatini stefasab at gmail.com
Mon Jan 16 00:06:45 CET 2012


On date Sunday 2012-01-15 23:20:57 +0100, Reimar Döffinger encoded:
> On Sun, Jan 15, 2012 at 11:08:55PM +0100, Stefano Sabatini wrote:
> > They allow to implement the if/then/else logic, which cannot be
> > implemented otherwise.
> > 
> > For example the expression:
> > A*B + not(A)*C
> > 
> > always evaluates to NaN if B is NaN, even in the case where A is 0.
> 
> Hmm. I guess we have no way to do that, bur casting to int would usually
> result in the NaN becoming 0.
> When and why is NaN a problem?

The property of NaN is that every operation with operand NaN will
evaluate to NaN, so the expression A*B + not(A)*C can't be used for
implementing an if/else logic (which is not semantically equivalent in
any case, since the evaluation of B may have side effects).

The problem I was tackling was that I needed to design a setpts
expression for setting NOPTS timestamps randomly in the output,
and I ended up with this one:
setpts=st(0\,lt(random(1)\,0.1))\; ifnonzero(ld(0)\,NaN) + ifzero(ld(0)\,PTS)
-- 
FFmpeg = Faithful Fiendish Majestic Proud Evangelical God


More information about the ffmpeg-devel mailing list