[FFmpeg-devel] [PATCH 11/13] doc/examples: removing polling from filtering examples.

Nicolas George nicolas.george at normalesup.org
Sun May 13 08:53:58 CEST 2012


Le quartidi 24 floréal, an CCXX, Clément Bœsch a écrit :
> diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
> index 2ca6a05..d8f466f 100644
> --- a/doc/examples/filtering_video.c
> +++ b/doc/examples/filtering_video.c
> @@ -205,13 +205,15 @@ int main(int argc, char **argv)
>                  av_vsrc_buffer_add_frame(buffersrc_ctx, &frame, 0);
>  
>                  /* pull filtered pictures from the filtergraph */
> -                while (avfilter_poll_frame(buffersink_ctx->inputs[0])) {
> -                    av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
> -                    if (picref) {
> -                        display_picref(picref, buffersink_ctx->inputs[0]->time_base);
> -                        avfilter_unref_buffer(picref);
> +                do {
> +                    ret = av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
> +                    if (ret < 0 && ret != AVERROR(EAGAIN)) {
> +                        av_log(NULL, AV_LOG_ERROR, "Error while getting buffer ref\n");
> +                        break;
>                      }
> -                }
> +                    display_picref(picref, buffersink_ctx->inputs[0]->time_base);
> +                    avfilter_unref_buffer(picref);
> +                } while (ret == AVERROR(EAGAIN));

Thanks for taking care of it, but I am afraid you got it wrong. It only
works because the example filter graph is so trivial: one-in-one-out.

If the filter does not return a frame immediately, we get EAGAIN, and this
code calls display_picref with an invalid picref.

If we fix that, the loop continues whine nothing has changed in the filter
graph, and it endlessly returns EAGAIN.

OTOH, if the filter outputs several frames for each input (do we have a
filter that does that? I thought yadif=2 would, but it does not seem so), it
will only read one before feeding more, thus accumulating frames in the
sink.

Additionally (but this is not new, and could be fixed separately), it does
not flush the filter.

The correct loop should look like this:

	while (1) {
	    ret = av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
	    if (ret < 0) {
		if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
		    av_log(...);
		break;
	    }
	    display_picref(picref);
	}

I am not sure I will be able to properly test and submit an updated version
in the next few days.

Regards,

-- 
  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/20120513/7da0a6ab/attachment.asc>


More information about the ffmpeg-devel mailing list