[FFmpeg-devel] [PATCH] examples/filtering_video: update to new API

Stefano Sabatini stefasab at gmail.com
Thu Mar 14 21:28:32 CET 2013


On date Thursday 2013-03-14 01:43:49 +0100, Clément Bœsch encoded:
> On Wed, Mar 13, 2013 at 09:57:09PM +0100, Stefano Sabatini wrote:
> > In particular, fix crash.
> > ---
> >  doc/examples/filtering_video.c |   38 ++++++++++++++++++--------------------
> >  1 file changed, 18 insertions(+), 20 deletions(-)
> > 
> > diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
> > index 8f2c1c7..251f0fe 100644
> > --- a/doc/examples/filtering_video.c
> > +++ b/doc/examples/filtering_video.c
> > @@ -138,33 +138,33 @@ static int init_filters(const char *filters_descr)
> >      return 0;
> >  }
> >  
> > -static void display_picref(AVFilterBufferRef *picref, AVRational time_base)
> > +static void display_frame(AVFrame *frame, AVRational time_base)
> 
> Note: same as before, the frame could possibly be made const in a later
> patch.

Yes, will do in a later patch.

[...]
> > @@ -213,23 +213,20 @@ int main(int argc, char **argv)
> >                  frame->pts = av_frame_get_best_effort_timestamp(frame);
> >  
> >                  /* push the decoded frame into the filtergraph */
> > -                if (av_buffersrc_add_frame(buffersrc_ctx, frame) < 0) {
> > +                if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
> 
> I think you can use av_buffersrc_write_frame() here.

For didactic reasons I prefer to mention the more powerful variant.

> 
> >                      av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
> >                      break;
> >                  }
> >  
> > -                /* pull filtered pictures from the filtergraph */
> > +                /* pull filtered frames from the filtergraph */
> >                  while (1) {
> > -                    ret = av_buffersink_get_buffer_ref(buffersink_ctx, &picref, 0);
> > +                    ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
> >                      if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
> >                          break;
> >                      if (ret < 0)
> >                          goto end;
> > -
> > -                    if (picref) {
> > -                        display_picref(picref, buffersink_ctx->inputs[0]->time_base);
> > -                        avfilter_unref_bufferp(&picref);
> > -                    }
> > +                    display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base);
> > +                    av_frame_unref(filt_frame);
> >                  }
> >              }
> >          }
> > @@ -240,7 +237,8 @@ end:
> >      if (dec_ctx)
> >          avcodec_close(dec_ctx);
> >      avformat_close_input(&fmt_ctx);
> > -    av_freep(&frame);
> > +    av_frame_free(&frame);
> > +    av_frame_free(&filt_frame);
> >  
> >      if (ret < 0 && ret != AVERROR_EOF) {
> >          char buf[1024];
> 
> Rest LGTM.

Will push it soon, thanks for the review.
-- 
FFmpeg = Funny and Fostering Magnificient Pitiful Erratic Gangster


More information about the ffmpeg-devel mailing list