[FFmpeg-devel] [PATCH] avfilter: add mergeplanes

Paul B Mahol onemda at gmail.com
Wed Oct 2 14:32:35 CEST 2013


On 10/1/13, Paul B Mahol <onemda at gmail.com> wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  doc/filters.texi             |  33 ++++
>  libavfilter/Makefile         |   1 +
>  libavfilter/allfilters.c     |   1 +
>  libavfilter/vf_mergeplanes.c | 356
> +++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 391 insertions(+)
>  create mode 100644 libavfilter/vf_mergeplanes.c
>

[...]

> +
> +static int config_output(AVFilterLink *outlink)
> +{
> +    AVFilterContext *ctx = outlink->src;
> +    MergePlanesContext *s = ctx->priv;
> +    FFFrameSyncIn *in = s->fs.in;
> +    enum AVPixelFormat pix_fmt;
> +    int depth[4][4];
> +    int i, j, k;
> +
> +    ff_framesync_init(&s->fs, ctx, s->nb_inputs);
> +    s->fs.opaque = s;
> +    s->fs.on_event = process_frame;
> +
> +    outlink->w = ctx->inputs[0]->w;
> +    outlink->h = ctx->inputs[0]->h;
> +    outlink->time_base = ctx->inputs[0]->time_base;
> +    outlink->frame_rate = ctx->inputs[0]->frame_rate;
> +    outlink->sample_aspect_ratio = ctx->inputs[0]->sample_aspect_ratio;
> +
> +    for (i = 0; i < s->nb_inputs; i++) {
> +        AVFilterLink *inlink = ctx->inputs[i];
> +        const AVPixFmtDescriptor *desc =
> av_pix_fmt_desc_get(inlink->format);
> +
> +        if (outlink->sample_aspect_ratio.num !=
> inlink->sample_aspect_ratio.num ||
> +            outlink->sample_aspect_ratio.den !=
> inlink->sample_aspect_ratio.den) {
> +            av_log(ctx, AV_LOG_ERROR, "input #%d link %s SAR %d:%d "
> +                                      "do not match output link %s SAR
> %d:%d\n",
> +                                      i, ctx->input_pads[i].name,
> +                                      inlink->sample_aspect_ratio.num,
> +                                      inlink->sample_aspect_ratio.den,
> +                                      ctx->output_pads[0].name,
> +                                      outlink->sample_aspect_ratio.num,
> +                                      outlink->sample_aspect_ratio.den);
> +            return AVERROR(EINVAL);
> +        }
> +
> +        s->planewidth[i][1]  =
> +        s->planewidth[i][2]  = FF_CEIL_RSHIFT(inlink->w,
> desc->log2_chroma_w);
> +        s->planewidth[i][0]  =
> +        s->planewidth[i][3]  = inlink->w;
> +        s->planeheight[i][1] =
> +        s->planeheight[i][2] = FF_CEIL_RSHIFT(inlink->h,
> desc->log2_chroma_h);
> +        s->planeheight[i][0] =
> +        s->planeheight[i][3] = inlink->h;
> +        s->nb_planes[i] = av_pix_fmt_count_planes(inlink->format);
> +        for (j = 0; j < s->nb_planes[i]; j++)
> +            depth[i][j] = desc->comp[j].depth_minus1;
> +
> +        in[i].time_base = inlink->time_base;
> +        in[i].sync   = 1;
> +        in[i].before = EXT_STOP;
> +        in[i].after  = EXT_STOP;
> +    }
> +
> +    i = 0;
> +    while ((pix_fmt = s->out[i]) != AV_PIX_FMT_NONE) {
> +        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
> +        int planewidth[4], planeheight[4];
> +        int nb_planes, plane = 0;
> +
> +        planewidth[1]  =
> +        planewidth[2]  = FF_CEIL_RSHIFT(outlink->w, desc->log2_chroma_w);
> +        planewidth[0]  =
> +        planewidth[3]  = outlink->w;
> +        planeheight[1] =
> +        planeheight[2] = FF_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h);
> +        planeheight[0] =
> +        planeheight[3] = outlink->h;
> +        nb_planes = av_pix_fmt_count_planes(pix_fmt);
> +
> +        for (j = 0; j < s->nb_inputs; j++) {
> +            for (k = 0; k < s->nb_planes[j]; k++, plane++) {
> +                if (plane >= nb_planes)
> +                    goto next;
> +                if (desc->comp[plane].depth_minus1 != depth[j][k])
> +                    goto next;
> +                if (planewidth[plane] != s->planewidth[j][k])
> +                    goto next;
> +                if (planeheight[plane] != s->planeheight[j][k])
> +                    goto next;
> +            }
> +        }
> +
> +        break;
> +next:
> +        i++;
> +    }
> +
> +    if (pix_fmt == AV_PIX_FMT_NONE) {
> +        av_log(ctx, AV_LOG_ERROR, "Failed to find format that matches
> inputs dimensions and/or depth.\n");
> +        return AVERROR(EINVAL);
> +    }
> +    outlink->format = pix_fmt;

This simply does not work due retarded design.

[...]


More information about the ffmpeg-devel mailing list