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

Clément Bœsch ubitux at gmail.com
Sun May 13 11:45:59 CEST 2012


On Sun, May 13, 2012 at 08:53:58AM +0200, Nicolas George wrote:
> 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.
> 

Argl indeed.

It's certainly overkill but having a motion estimation filter to insert N
frames between each couple of frames might make use of this feature.
Doesn't FFmpeg already have all the builtins for this kind of stuff?

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

Right; the examples are not perfect, and some use quite deprecated stuff
too.

> 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 will update the patch soon, thanks. Not sure I'll be able to test it
properly though.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120513/cbbdb225/attachment.asc>


More information about the ffmpeg-devel mailing list