[FFmpeg-devel] [PATCH 1/2] lavfi/removelogo: switch to ff_filter_frame.

Clément Bœsch ubitux at gmail.com
Mon Dec 3 00:13:45 CET 2012


On Mon, Dec 03, 2012 at 12:05:49AM +0100, Stefano Sabatini wrote:
> On date Sunday 2012-12-02 21:33:58 +0100, Clément Bœsch encoded:
> > ---
> >  libavfilter/vf_removelogo.c | 45 ++++++++++++++++++++++-----------------------
> >  1 file changed, 22 insertions(+), 23 deletions(-)
> > 
> > diff --git a/libavfilter/vf_removelogo.c b/libavfilter/vf_removelogo.c
> > index f2228be..f3d8d7b 100644
> > --- a/libavfilter/vf_removelogo.c
> > +++ b/libavfilter/vf_removelogo.c
> > @@ -72,6 +72,7 @@
> >  #include "libavutil/imgutils.h"
> >  #include "avfilter.h"
> >  #include "formats.h"
> > +#include "internal.h"
> >  #include "video.h"
> >  #include "bbox.h"
> >  #include "lavfutils.h"
> > @@ -472,24 +473,24 @@ static void blur_image(int ***mask,
> >      }
> >  }
> >  
> > -static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
> > -{
> > -    AVFilterLink *outlink = inlink->dst->outputs[0];
> > -    AVFilterBufferRef *outpicref;
> > -
> > -    outpicref = inpicref;
> > -
> > -    outlink->out_buf = outpicref;
> > -    return ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
> > -}
> > -
> > -static int end_frame(AVFilterLink *inlink)
> > +static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
> >  {
> >      RemovelogoContext *removelogo = inlink->dst->priv;
> >      AVFilterLink *outlink = inlink->dst->outputs[0];
> > -    AVFilterBufferRef *inpicref  = inlink ->cur_buf;
> > -    AVFilterBufferRef *outpicref = outlink->out_buf;
> > -    int direct = inpicref == outpicref;
> > +    AVFilterBufferRef *outpicref;
> > +    int direct = 0;
> > +
> > +    if (inpicref->perms & AV_PERM_WRITE) {
> > +        direct = 1;
> > +        outpicref = inpicref;
> > +    } else {
> > +        outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
> > +        if (!outpicref) {
> > +            avfilter_unref_bufferp(&inpicref);
> > +            return AVERROR(ENOMEM);
> > +        }
> > +        avfilter_copy_buffer_ref_props(outpicref, inpicref);
> > +    }
> >  
> >      blur_image(removelogo->mask,
> >                 inpicref ->data[0], inpicref ->linesize[0],
> > @@ -507,8 +508,10 @@ static int end_frame(AVFilterLink *inlink)
> >                 removelogo->half_mask_data, inlink->w/2,
> >                 inlink->w/2, inlink->h/2, direct, &removelogo->half_mask_bbox);
> >  
> > -    ff_draw_slice(outlink, 0, inlink->h, 1);
> > -    return ff_end_frame(outlink);
> > +    if (!direct)
> > +        avfilter_unref_bufferp(&inpicref);
> > +
> > +    return ff_filter_frame(outlink, outpicref);
> >  }
> >  
> >  static void uninit(AVFilterContext *ctx)
> > @@ -533,18 +536,14 @@ static void uninit(AVFilterContext *ctx)
> >      }
> >  }
> >  
> > -static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
> > -
> >  static const AVFilterPad removelogo_inputs[] = {
> >      {
> >          .name             = "default",
> >          .type             = AVMEDIA_TYPE_VIDEO,
> >          .get_video_buffer = ff_null_get_video_buffer,
> >          .config_props     = config_props_input,
> > -        .draw_slice       = null_draw_slice,
> > -        .start_frame      = start_frame,
> > -        .end_frame        = end_frame,
> > -        .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
> > +        .filter_frame     = filter_frame,
> 
> > +        .min_perms        = AV_PERM_READ,
> 
> I suppose this is unrelated, right?
> 

It is related: if I don't remove the AV_PERM_WRITE the inpicref will
always have the write flag and the in-place processing (direct flag) won't
be triggered.

> LGTM if tested and nice patch, thanks.

It's somehow related to what we decide to do with hqdn3d and gradfun
filters, so I'll wait a little before pushing this.

-- 
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/20121203/9c09384c/attachment.asc>


More information about the ffmpeg-devel mailing list