[FFmpeg-devel] [PATCH] avfilter: add pad opencl filter

Mark Thompson sw at jkqxz.net
Fri Feb 14 01:21:15 EET 2020


On 10/02/2020 12:03, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  configure                   |   1 +
>  doc/filters.texi            |  77 +++++++
>  libavfilter/Makefile        |   1 +
>  libavfilter/allfilters.c    |   1 +
>  libavfilter/opencl/pad.cl   |  36 ++++
>  libavfilter/opencl_source.h |   1 +
>  libavfilter/vf_pad_opencl.c | 397 ++++++++++++++++++++++++++++++++++++
>  7 files changed, 514 insertions(+)
>  create mode 100644 libavfilter/opencl/pad.cl
>  create mode 100644 libavfilter/vf_pad_opencl.c
> 
> ...
> +
> +The @var{x} expression can reference the value set by the @var{y}
> +expression, and vice versa.
> +
> +The default value of @var{x} and @var{y} is 0.
> +
> +If @var{x} or @var{y} evaluate to a negative number, they'll be changed
> +so the input image is centered on the padded area.
> +
> + at item color
> +Specify the color of the padded area. For the syntax of this option,
> +check the @ref{color syntax,,"Color" section in the ffmpeg-utils
> +manual,ffmpeg-utils}.
> +
> + at item aspect
> +Pad to aspect instead to a resolution.

Funny phrasing.  "Pad to an aspect ratio instead of to a resolution.", maybe.

> + at end table
> +
> +The value for the @var{width}, @var{height}, @var{x}, and @var{y}
> +options are expressions containing the following constants:
> +
> + at table @option
> + at item in_w
> + at item in_h
> +The input video width and height.
> +
> + at item iw
> + at item ih
> +These are the same as @var{in_w} and @var{in_h}.
> +
> ...
> +
> +static int pad_opencl_init(AVFilterContext *avctx, AVFrame *input_frame)
> +{
> +    PadOpenCLContext *ctx = avctx->priv;
> +    AVHWFramesContext *input_frames_ctx = (AVHWFramesContext *)input_frame->hw_frames_ctx->data;
> +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(input_frames_ctx->sw_format);
> +    uint8_t rgba_map[4];
> +    cl_int cle;
> +    int err;
> +
> +    ff_fill_rgba_map(rgba_map, input_frames_ctx->sw_format);

Ah, cute.  It's nice that a function already exists for this case :)

> +    ctx->is_rgb = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
> +    ctx->is_packed = !(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
> +    ctx->hsub = desc->log2_chroma_w;
> +    ctx->vsub = desc->log2_chroma_h;
> +
> +    err = ff_opencl_filter_load_program(avctx, &ff_opencl_source_pad, 1);
> +    if (err < 0)
> +        goto fail;
> +
> ...

I tested a bit on Mali and everything else LGTM.

Thanks,

- Mark


More information about the ffmpeg-devel mailing list