[FFmpeg-devel] [PATCH] Add alphaextract, alphamerge filters

Nicolas George nicolas.george at normalesup.org
Sun Jul 15 01:03:36 CEST 2012

Le septidi 27 messidor, an CCXX, Steven Robertson a écrit :
> It works in all cases that I've tested. I agree that timestamps would guard
> against that problem, but I also agree that they would be more complicated ;)
> I'd prefer to get this in in its simpler form and wait for that API to become
> available.

I have no objection to that, but maybe a small warning in the doc may be in

> I'm not sure I get the intent here. I came up with this, which I believe will
> work for the cases I can think of. If it doesn't, can you help me understand
> why?
>     if (!ff_bufqueue_peek(&merge->queue_alpha, 0)) {
>       ret = ff_request_frame(ctx->inputs[1]);
>       if (ret < 0)
>           return ret;
>     }
>     if (!ff_bufqueue_peek(&merge->queue_main, 0)) {
>       ret = ff_request_frame(ctx->inputs[0]);
>       if (ret < 0)
>           return ret;
>     }
>     return 0;

Unfortunately, that may not work.

Imagine you have the luminance and alpha side by side in a single video: you
use a split and two crops to separate them, and then alphamerge. Or maybe
you use alphaextract, then do a transform on one of the streams and merge
them again.

When you do your first request, it goes back to the split filter, and it
reacts by sending a frame on both streams. The frames arrive to alphamerge,
there is enough to produce output, so both frames are consumed. Then you
arrive to the second ff_bufqueue_peek: as the frame that just arrived on
input #0 has been consumed, the condition is true: the code ends up
requesting a second frame from the split, and thus sending two frames when
only one was requested, or returning an error code when in fact filtering
was succesfull.

Filters with multiple inputs are very tricky, because frames can arrive on
any input at inconvenient times. If anyone has suggestions on how to make
them less so, they are very welcome.

I will try to comment the new version of the patch a little later.


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120715/1111cb8c/attachment.asc>

More information about the ffmpeg-devel mailing list