[FFmpeg-devel] [PATCH 2/2] libavutil/libavfilter: deshake opencl filter based on comments on 20130326

Michael Niedermayer michaelni at gmx.at
Tue Mar 26 23:00:18 CET 2013


On Tue, Mar 26, 2013 at 06:56:13PM +0800, Wei Gao wrote:
> 

>  configure                      |    1 
>  libavfilter/Makefile           |    2 
>  libavfilter/allfilters.c       |   22 ++++
>  libavfilter/deshake_kernel.h   |  211 +++++++++++++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.c |  155 ++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.h |   67 +++++++++++++
>  libavfilter/vf_deshake.c       |  175 +++++++++++++++++++++++++++++++++-
>  7 files changed, 631 insertions(+), 2 deletions(-)
> 8b250f8cbfe782b4b0bc40c2bdab8ddf2a2ee726  0002-deshake-opencl-filter-based-on-comments-on-20130326.patch
> From de9b4e534d828b66e70e3f18de63bdd7c3c11db9 Mon Sep 17 00:00:00 2001
> From: highgod0401 <highgod0401 at gmail.com>
> Date: Tue, 26 Mar 2013 18:52:30 +0800
> Subject: [PATCH 2/2] deshake opencl filter based on comments on 20130326
> 
> ---
>  configure                      |   1 +
>  libavfilter/Makefile           |   2 +
>  libavfilter/allfilters.c       |  22 ++++-
>  libavfilter/deshake_kernel.h   | 211 +++++++++++++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.c | 155 ++++++++++++++++++++++++++++++
>  libavfilter/transform_opencl.h |  67 +++++++++++++
>  libavfilter/vf_deshake.c       | 175 +++++++++++++++++++++++++++++++++-
>  7 files changed, 631 insertions(+), 2 deletions(-)
>  create mode 100644 libavfilter/deshake_kernel.h
>  create mode 100644 libavfilter/transform_opencl.c
>  create mode 100644 libavfilter/transform_opencl.h
> 
> diff --git a/configure b/configure
> index 9c42a85..531e753 100755
> --- a/configure
> +++ b/configure
> @@ -2088,6 +2088,7 @@ cropdetect_filter_deps="gpl"
>  decimate_filter_deps="gpl avcodec"
>  delogo_filter_deps="gpl"
>  deshake_filter_deps="avcodec"
> +deshake_opencl_filter_deps="opencl deshake_filter"
>  drawtext_filter_deps="libfreetype"
>  ebur128_filter_deps="gpl"
>  flite_filter_deps="libflite"
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 0040a33..b91b802 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -9,6 +9,7 @@ FFLIBS-$(CONFIG_ASYNCTS_FILTER)              += avresample
>  FFLIBS-$(CONFIG_ATEMPO_FILTER)               += avcodec
>  FFLIBS-$(CONFIG_DECIMATE_FILTER)             += avcodec
>  FFLIBS-$(CONFIG_DESHAKE_FILTER)              += avcodec
> +FFLIBS-$(CONFIG_DESHAKE_OPENCL_FILTER)       += avcodec
>  FFLIBS-$(CONFIG_MOVIE_FILTER)                += avformat avcodec
>  FFLIBS-$(CONFIG_MP_FILTER)                   += avcodec
>  FFLIBS-$(CONFIG_PAN_FILTER)                  += swresample
> @@ -109,6 +110,7 @@ OBJS-$(CONFIG_CURVES_FILTER)                 += vf_curves.o
>  OBJS-$(CONFIG_DECIMATE_FILTER)               += vf_decimate.o
>  OBJS-$(CONFIG_DELOGO_FILTER)                 += vf_delogo.o
>  OBJS-$(CONFIG_DESHAKE_FILTER)                += vf_deshake.o
> +OBJS-$(CONFIG_DESHAKE_OPENCL_FILTER)         += vf_deshake.o transform_opencl.o
>  OBJS-$(CONFIG_DRAWBOX_FILTER)                += vf_drawbox.o
>  OBJS-$(CONFIG_DRAWTEXT_FILTER)               += vf_drawtext.o
>  OBJS-$(CONFIG_EDGEDETECT_FILTER)             += vf_edgedetect.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 086e6c9..53af870 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -21,7 +21,10 @@
>  
>  #include "avfilter.h"
>  #include "config.h"
> -
> +#if CONFIG_OPENCL
> +#include "libavutil/opencl.h"
> +#include "deshake_kernel.h"
> +#endif
>  
>  #define REGISTER_FILTER(X, x, y)                                        \
>      {                                                                   \
> @@ -35,7 +38,21 @@
>          extern AVFilter avfilter_##x;                                   \
>          avfilter_register(&avfilter_##x);                               \
>      }
> +#if CONFIG_OPENCL
> +#define OPENCL_REGISTER_FILTER(X, x, y)                                          \
> +    {                                                                            \
> +        extern AVFilter avfilter_##y##_##x;                                      \
> +        if (CONFIG_##X##_FILTER) {                                               \
> +            avfilter_register(&avfilter_##y##_##x);                              \

> +            av_opencl_register_kernel((avfilter_##y##_##x).name,ff_kernel_##x);  \

compiling the kernel at registration is not ideal.
Consider there are 50 filters with opencl, its very unlikely more
then 3 will be used during runtime. compiling or loading the others
is a waste of time.

[...]

> +#if CONFIG_DESHAKE_OPENCL_FILTER
> +    if (deshake->is_opencl) {
> +        int ret = 0;

> +        if ((!deshake->opencl_env.cl_inbuf.cl_buf) || (deshake->opencl_env.cl_outbuf.cl_buf)) {

is this supposed to be !A || B or !A || !B ?


[...]
> +#endif
> +
>  
>  static const AVFilterPad deshake_inputs[] = {
>      {
> @@ -583,3 +723,36 @@ AVFilter avfilter_vf_deshake = {
>      .outputs       = deshake_outputs,
>      .priv_class    = &deshake_class,
>  };
> +
> +#if CONFIG_DESHAKE_OPENCL_FILTER
> +
> +static const AVFilterPad deshake_opencl_inputs[] = {
> +    {
> +        .name         = "default",
> +        .type         = AVMEDIA_TYPE_VIDEO,
> +        .filter_frame = filter_frame,
> +        .config_props = config_props,
> +    },
> +    { NULL }
> +};
> +
> +static const AVFilterPad deshake_opencl_outputs[] = {
> +    {
> +        .name = "default",
> +        .type = AVMEDIA_TYPE_VIDEO,
> +    },
> +    { NULL }
> +};
> +
> +AVFilter avfilter_vf_deshake_opencl = {
> +    .name          = "deshake_opencl",
> +    .description   = NULL_IF_CONFIG_SMALL("Stabilize shaky video using OpenCL."),
> +    .priv_size     = sizeof(DeshakeContext),
> +    .init          = init_opencl,
> +    .uninit        = uninit_opencl,
> +    .query_formats = query_formats,
> +    .inputs        = deshake_opencl_inputs,
> +    .outputs       = deshake_opencl_outputs,
> +    .priv_class    = &deshake_class,
> +};
> +#endif

opencl code should not be interleaved with #ifdefs into filters
this would be unmaintainable especially with complexer filters

the opencl code should be put in seperate file(s) and either used
like SIMD optimizations through function pointers or by including a
header with opencl code if thats not possible
Other solutions are of course possible too but such mixing with ifdefs
is not a good idea, it would make it also hard for you to
maintain the code in the future ...

Thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130326/56f4437f/attachment.asc>


More information about the ffmpeg-devel mailing list