[FFmpeg-devel] [PATCH] lavfi/color: cache and reuse colored picture in context

Stefano Sabatini stefasab at gmail.com
Sun Jul 29 20:40:13 CEST 2012


On date Sunday 2012-07-29 17:27:00 +0200, Nicolas George encoded:
> Le duodi 12 thermidor, an CCXX, Stefano Sabatini a écrit :
[...]
> >  static int query_formats(AVFilterContext *ctx)
> >  {
> >      ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
> > @@ -124,18 +131,24 @@ static int color_config_props(AVFilterLink *inlink)
> >  static int color_request_frame(AVFilterLink *link)
> >  {
> >      ColorContext *color = link->src->priv;
> > -    AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
> >      AVFilterBufferRef *buf_out;
> >      int ret;
> >  
> > -    if (!picref)
> > -        return AVERROR(ENOMEM);
> > -
> > -    picref->video->sample_aspect_ratio = (AVRational) {1, 1};
> > -    picref->pts = color->pts++;
> > -    picref->pos = -1;
> > +    if (!color->picref) {
> > +        color->picref =
> > +            ff_get_video_buffer(link, AV_PERM_WRITE|AV_PERM_REUSE,
> > +                                color->w, color->h);
> > +        if (!color->picref)
> > +            return AVERROR(ENOMEM);
> > +        ff_fill_rectangle(&color->draw, &color->color,
> > +                          color->picref->data, color->picref->linesize,
> > +                          0, 0, color->w, color->h);
> > +        color->picref->video->sample_aspect_ratio = (AVRational) {1, 1};
> > +        color->picref->pos = -1;
> > +    }
> >  
> > -    buf_out = avfilter_ref_buffer(picref, ~0);
> > +    color->picref->pts = color->pts++;
> 
> > +    buf_out = avfilter_ref_buffer(color->picref, ~0);
> 
> If you do not remove WRITE, the next filter may write in the original buffer
> and its result will stay on all frames. I predict that "drawtext=x=t*10:..."
> would leave a sludge.
> 
> PRESERVE may help avoid a few useless copies, but that I am not completely
> sure about.

Updated.
-- 
FFmpeg = Freak and Fast Multimedia Philosofic Exciting Guide
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-lavfi-color-cache-and-reuse-colored-picture-in-conte.patch
Type: text/x-diff
Size: 3230 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120729/b2ffe4a2/attachment.bin>


More information about the ffmpeg-devel mailing list