[FFmpeg-devel] [PATCH] lavfi: add smartblur filter

Clément Bœsch ubitux at gmail.com
Tue Aug 28 02:53:14 CEST 2012


On Tue, Aug 28, 2012 at 02:32:58AM +0200, Jérémy Tran wrote:
> This is a port of the MPlayer smartblur filter (libmpcodecs/vf_smartblur.c)
> by Michael Niedermayer.
> The code got relicensed to the LGPL with the original author permission.
> ---
>  configure                  |   1 +
>  doc/filters.texi           |  26 ++++
>  libavfilter/Makefile       |   2 +
>  libavfilter/allfilters.c   |   1 +
>  libavfilter/vf_smartblur.c | 306 +++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 336 insertions(+)
>  create mode 100644 libavfilter/vf_smartblur.c
> 
> diff --git a/configure b/configure
> index 0b95927..4b22024 100755
> --- a/configure
> +++ b/configure
> @@ -1847,6 +1847,7 @@ ocv_filter_deps="libopencv"
>  pan_filter_deps="swresample"
>  removelogo_filter_deps="avcodec avformat swscale"
>  scale_filter_deps="swscale"
> +smartblur_filter_deps="swscale"
>  select_filter_deps="avcodec"
>  showspectrum_filter_deps="avcodec"
>  super2xsai_filter_deps="gpl"
> diff --git a/doc/filters.texi b/doc/filters.texi
> index bef95f7..fce45d4 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3253,6 +3253,32 @@ not specified it will use the default value of 16.
>  Adding this in the beginning of filter chains should make filtering
>  faster due to better use of the memory cache.
>  
> + at section smartblur
> +
> +Blur the input video without impacting the outlines.
> +
> +The filter accepts the following parameters:
> + at var{luma_radius}:@var{luma_strength}:@var{luma_threshold}[:@var{chroma_radius}:@var{chroma_strength}:@var{chroma_threshold}]
> +
> +Parameters prefixed by @var{luma} indicate that it work on the luminance of the

s/work/works/ ?

> +pixels whereas parameters prefixed by @var{chroma} refer to the chrominance of
> +the pixels.
> +
> +If the chroma parameters are not set, the luma parameters are used for
> +either the luminance and the chrominance of the pixels.
> +
> + at var{luma_radius} or @var{chroma_radius} must be a float number in the range [0.1,5.0] that specifies
> +the variance of the gaussian filter used to blur the image (slower if larger).
> +
> + at var{luma_strength} or @var{chroma_strength} must be a float number in the range [-1.0,1.0] that
> +configures the blurring. A value included in [0.0,1.0] will blur the image
> +whereas a value included in [-1.0,0.0] will sharpen the image.
> +
> + at var{luma_threshold} or @var{chroma_threshold} must be an integer in the range [-30,30] that is used as a
> +coefficient to determine whether a pixel should be blurred or not. A value of
> +0 will filter all the image, a value included in [0-30] will filter flat areas

[0,-30]

> +and a value included in [-30,0] will filter edges.
> +
>  @section split
>  
[...]
> +typedef struct {
> +    float              radius;
> +    float              strength;
> +    int                threshold;
> +    float              quality;
> +    struct SwsContext *filter_context;
> +} FilterParam;
> +
> +typedef struct {
> +    FilterParam  luma;
> +    FilterParam  chroma;
> +    int          hsub;
> +    int          vsub;
> +    unsigned int flags; // sws flags

maybe it would make sense to call it sws_flags then.

> +} SmartblurContext;
> +
> +#define CHECK_PARAM(param, name, min, max, format, ret)                       \
> +    if (param < min || param > max) {                                         \
> +        av_log(ctx, AV_LOG_ERROR,                                             \
> +               "Invalid " #name " value " #format ": "                        \
> +               "must be included between range " #format " and " #format "\n",\
> +               param, min, max);                                              \
> +        ret = AVERROR(EINVAL);                                                \
> +    }
> +
> +static av_cold int init(AVFilterContext *ctx, const char *args)
> +{
> +    SmartblurContext *sblur = ctx->priv;
> +    int n = 0, ret = 0;
> +    float lradius, lstrength, cradius, cstrength;
> +    int lthreshold, cthreshold;
> +
> +    if (args)
> +        n = sscanf(args, "%f:%f:%d:%f:%f:%d",

> +                   &lradius,
> +                   &lstrength,
> +                   &lthreshold,
> +                   &cradius,
> +                   &cstrength,
> +                   &cthreshold);

nit: 2 lines instead of 6 for these might enlight the relationship between
luma & chroma settings.

[...]

No other comment from me; good work overall, thanks.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120828/6f2bf730/attachment.asc>


More information about the ffmpeg-devel mailing list