[FFmpeg-devel] Copyplane filter

Gavin Kinsey gkinsey at ad-holdings.co.uk
Thu Aug 25 09:07:37 CEST 2011


On Thursday 25 August 2011 01:00:05 Stefano Sabatini wrote:
> On date Wednesday 2011-08-24 10:37:34 +0100, Gavin Kinsey encoded:
> > +
> > +typedef struct {
> > +    const AVClass *class;
> > +    char   *comp_expr_str[4];
> > 
> > +    AVExpr *comp_expr[4];
> 
> is this ever used?

Good catch, removed.

> 
> [...]
> 
> > +static void draw_slice(AVFilterLink *inlink, int y, int h, int
> > slice_dir) +{
> > +    CopyPlaneContext *cp      = inlink->dst->priv;
> > +    AVFilterBufferRef *inpic  = inlink->cur_buf;
> > +    AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
> > +    int i, c, w = inlink->w;
> > +
> > +    for (c = 0; c < cp->pix_desc->nb_components; c++) {
> > +        int w1 = c == 1 || c == 2 ? w>>cp->pix_desc->log2_chroma_w :
> > w; +        int h1 = c == 1 || c == 2 ? h>>cp->pix_desc->log2_chroma_h
> > : h; +        int y1 = c == 1 || c == 2 ?
> > y>>cp->pix_desc->log2_chroma_h : y; +
> > +        for (i = y1; i < y1 + h1; i++) {
> > +            if (cp->copyplane[c] >= 0)  {
> > +                av_read_image_line(cp->line,
> > +                                   (const uint8_t **)inpic->data,
> > +                                   inpic->linesize,
> > +                                   cp->pix_desc,
> > +                                   0, i, cp->copyplane[c], w1, 0);
> > +                av_write_image_line(cp->line,
> > +                                    outpic->data,
> > +                                    outpic->linesize,
> > +                                    cp->pix_desc,
> > +                                    0, i, c, w1);
> > +            }
> > +            if (!cp->skipplane[c])  {
> > +                av_read_image_line(cp->line,
> > +                                   (const uint8_t **)inpic->data,
> > +                                   inpic->linesize,
> > +                                   cp->pix_desc,
> > +                                   0, i, c, w1, 0);
> > +                av_write_image_line(cp->line,
> > +                                    outpic->data,
> > +                                    outpic->linesize,
> > +                                    cp->pix_desc,
> > +                                    0, i, c, w1);
> > +            }
> 
> Look, since you don't need generic support a simple memcpy should be
> more efficient.

A memcpy per line or is just one per plane safe?

> Also note that this filter job can be done in a much more general way
> using an eval filter, e.g.:
> 
> evalrgb=a=r
> 
> Check the applyfn filter in the archive, also you could consider using
> the mp=geq filter (not sure it supports alpha).

I looked at the existing filters, didn't think to look for ones that haven't 
been applied, or the mplayer ones.  I'll take a look, since even if I don't 
use one now it may be useful in future, or for reference.

> On the other hand the eval filter would be much slower (an expression
> is evaluated for each pixel component), so maybe the copyplane idea is
> acceptable.

Performance is an issue, since our apps often run multiple streams in 
parallel.  I'll do some tests and see what the performance difference is for 
our typical workloads.  But to be honest now I've gone to the effort of 
writing it I'll probably just stick with copyplane.  :-)

-- 
Gavin Kinsey
AD Holdings Plc


Closed IPTV, the new safe and secure deterministic IP Video solution from Dedicated Micros, is now shipping through selected distributors.
- Come and see this award winning plug and play, IP Video innovation at one of our Roadshows around the UK visit: https://www.dedicatedmicros.com/europe/ClosedIPTVRoadshow2011
- Contact our Customer Services Team for more information regarding how to enter the world of safe and secure hybrid IP and analogue video surveillance systems.


More information about the ffmpeg-devel mailing list