[FFmpeg-devel] [PATCH] smptebars filter

Paul B Mahol onemda at gmail.com
Wed Jun 20 19:05:02 CEST 2012


On 6/20/12, Clement Boesch <ubitux at gmail.com> wrote:
> On Wed, Jun 20, 2012 at 01:54:58AM +0000, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
[...]
> +    ff_fill_rectangle(&smpte->draw, &color, picref->data,
>> picref->linesize, x, r_h + w_h, r_w / 3, p_h);
>> +    x += r_w / 3;
>> +    ff_draw_color(&smpte->draw, &color, black);
>> +    ff_fill_rectangle(&smpte->draw, &color, picref->data,
>> picref->linesize, x, r_h + w_h, r_w / 3, p_h);
>> +    x += r_w / 3;
>> +    ff_draw_color(&smpte->draw, &color, pos4ire);
>> +    ff_fill_rectangle(&smpte->draw, &color, picref->data,
>> picref->linesize, x, r_h + w_h, r_w / 3, p_h);
>> +    x += r_w / 3;
>> +    ff_draw_color(&smpte->draw, &color, black);
>> +    ff_fill_rectangle(&smpte->draw, &color, picref->data,
>> picref->linesize, x, r_h + w_h, smpte->w - x, p_h);
>
> Can't you draw only a big black rectangle at the bottom of the frame and
> then add the other colors?

I do not like that idea.

>
>> +}
>> +
>> +static int request_frame(AVFilterLink *outlink)
>> +{
>> +    SMPTEBarsContext *smpte = outlink->src->priv;
>> +    AVFilterBufferRef *picref;
>> +
>> +    picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, smpte->w,
>> smpte->h);
>> +    picref->video->sample_aspect_ratio = smpte->sar;
>> +
>> +    ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
>> +    draw_smptebars(outlink->src, picref);
>> +    ff_draw_slice(outlink, 0, picref->video->h, 1);
>> +    ff_end_frame(outlink);
>> +    avfilter_unref_buffer(picref);
>> +    return 0;
>> +}
>> +
>
> Wouldn't it be possible to draw the buffer only once (in config_props for
> instance) and making it RO so we it will be faster?

I dunno if there is any filter which actually does that.

>
>> +static int config_props(AVFilterLink *outlink)
>> +{
>> +    AVFilterContext *ctx = outlink->src;
>> +    SMPTEBarsContext *smpte = ctx->priv;
>> +
>> +    ff_draw_init(&smpte->draw, outlink->format, 0);
>> +
>> +    if (av_image_check_size(smpte->w, smpte->h, 0, ctx) < 0)
>> +        return AVERROR(EINVAL);
>> +
>> +    outlink->w = smpte->w;
>> +    outlink->h = smpte->h;
>> +    outlink->sample_aspect_ratio = smpte->sar;
>> +    outlink->time_base = smpte->time_base;
>> +
>> +    return 0;
>> +}
>> +
>> +AVFilter avfilter_vsrc_smptebars = {
>> +    .name      = "smptebars",
>> +    .description = NULL_IF_CONFIG_SMALL("Generate SMPTE color bars."),
>> +    .priv_size = sizeof(SMPTEBarsContext),
>> +    .init      =  smptebars_init,
>> +
>> +    .query_formats   = smptebars_query_formats,
>> +
>> +    .inputs    = (const AVFilterPad[]) {{ .name = NULL}},
>> +
>> +    .outputs   = (const AVFilterPad[]) {{ .name = "default",
>> +                                    .type = AVMEDIA_TYPE_VIDEO,
>> +                                    .request_frame = request_frame,
>> +                                    .config_props  = config_props, },
>> +                                  { .name = NULL }},
>> +};
>
> Also, does the spec have some kind requirements about the SAR, or
> colorspace?

Nice one, spec have nothing to do with YUV or RGB colorspace.

This filters just emulates y4mcolorbars (see trac issue #1462).


More information about the ffmpeg-devel mailing list