[FFmpeg-devel] [PATCH] lavfi: Port fspp to FFmpeg

Stefano Sabatini stefasab at gmail.com
Thu Dec 25 10:19:52 CET 2014


On date Thursday 2014-12-25 10:02:05 +0530, arwa arif encoded:
> Merry Christmas! :D
> 
> I have attached 2 patches:
> 1. For deleting the mp=fspp filter.
> 2. For porting pp7
> 
> I have tested the ouput for pp7, it is bitexact with mp=pp7 filter. Also, I
> haven't completed the patch. There are just codes. Once the previous
> patches are pushed, I will update the patch.

> From 93138917e7da3bd66602fb44579f85cf6e6e6f6a Mon Sep 17 00:00:00 2001
> From: Arwa Arif <arwaarif1994 at gmail.com>
> Date: Thu, 25 Dec 2014 09:33:29 +0530
> Subject: [PATCH] lavfi: Delete mp=fspp
> 
> ---
>  doc/filters.texi                  |    1 -
>  libavfilter/Makefile              |    1 -
>  libavfilter/libmpcodecs/vf_fspp.c | 2124 -------------------------------------
>  libavfilter/vf_mp.c               |    2 -
>  4 files changed, 2128 deletions(-)
>  delete mode 100644 libavfilter/libmpcodecs/vf_fspp.c

I already removed mp=fspp, see commit:
commit a51c78c65d596a6473a8f08e925a35249944e449
Author: Stefano Sabatini <stefasab at gmail.com>
Date:   Wed Dec 24 16:19:29 2014 +0100

    lavfi/mp: drop mp=fspp filter
    
    It has been ported to libavfilter.

[...]
> From e0d07f8b67dce226713b49db775ffd1ee1e401e4 Mon Sep 17 00:00:00 2001
> From: Arwa Arif <arwaarif1994 at gmail.com>
> Date: Thu, 25 Dec 2014 09:50:24 +0530
> Subject: [PATCH] lavfi: port mp=pp7 to avfilter

Please post this to a new dedicated thread at the next iteration.
 
> ---
>  libavfilter/vf_pp7.c     |  500 ++++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/vf_pp7.h     |   57 ++++++
>  libavfilter/x86/vf_pp7.c |   74 +++++++
>  3 files changed, 631 insertions(+)
>  create mode 100644 libavfilter/vf_pp7.c
>  create mode 100644 libavfilter/vf_pp7.h
>  create mode 100644 libavfilter/x86/vf_pp7.c

missing gpl dependencies in configure, missing docs.
 
> diff --git a/libavfilter/vf_pp7.c b/libavfilter/vf_pp7.c
> new file mode 100644
> index 0000000..9c2b4bb
> --- /dev/null
> +++ b/libavfilter/vf_pp7.c
> @@ -0,0 +1,500 @@
> +/*
> + * Copyright (c) 2005 Michael Niedermayer <michaelni at gmx.at>
> + * Copyright (c) 2014 Arwa Arif <arwaarif1994 at gmail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +/**
> + * @file
> + * Postprocessing filter - 7
> + *
> + * Originally written by Michael Niedermayer for the MPlayer
> + * project, and ported by Arwa Arif for FFmpeg.
> + */
> +
> +#include "libavutil/avassert.h"
> +#include "libavutil/imgutils.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "internal.h"
> +#include "libavcodec/avcodec.h" //for reference to FF_QSCALE_TYPE
> +#include "vf_pp7.h"
> +
> +enum mode {
> +    MODE_HARD,
> +    MODE_SOFT,
> +    MODE_MEDIUM
> +};
> +
> +#define OFFSET(x) offsetof(PP7Context, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +static const AVOption pp7_options[] = {
> +    { "qp", "force a constant quantizer parameter", OFFSET(qp), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 64, FLAGS },
> +    { "mode", "set thresholding mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MODE_MEDIUM}, 0, 2, FLAGS, "mode" },
> +        { "hard",   "hard thresholding",   0, AV_OPT_TYPE_CONST, {.i64 = MODE_HARD},   INT_MIN, INT_MAX, FLAGS, "mode" },
> +        { "soft",   "soft thresholding",   0, AV_OPT_TYPE_CONST, {.i64 = MODE_SOFT},   INT_MIN, INT_MAX, FLAGS, "mode" },
> +        { "medium", "medium thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_MEDIUM}, INT_MIN, INT_MAX, FLAGS, "mode" },

> +    { "use_bframe_qp", "use B-frames' QP", OFFSET(use_bframe_qp), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },

This parameter is not present in the original code, mention this in
the log (alternatively you could add it in a separate commit).

> +    { NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(pp7);
> +
> +DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
> +    {  0,  48,  12,  60,   3,  51,  15,  63, },
> +    { 32,  16,  44,  28,  35,  19,  47,  31, },
> +    {  8,  56,   4,  52,  11,  59,   7,  55, },
> +    { 40,  24,  36,  20,  43,  27,  39,  23, },
> +    {  2,  50,  14,  62,   1,  49,  13,  61, },
> +    { 34,  18,  46,  30,  33,  17,  45,  29, },
> +    { 10,  58,   6,  54,   9,  57,   5,  53, },
> +    { 42,  26,  38,  22,  41,  25,  37,  21, },
> +};
> +

> +static const int factor[16] = {
> +    N / (N0 * N0), N / (N0 * N1), N / (N0 * N0), N / (N0 * N2),
> +    N / (N1 * N0), N / (N1 * N1), N / (N1 * N0), N / (N1 * N2),
> +    N / (N0 * N0), N / (N0 * N1), N / (N0 * N0), N / (N0 * N2),
> +    N / (N2 * N0), N / (N2 * N1), N / (N2 * N0), N / (N2 * N2),
> +};
> +
> +static const int thres[16] = {
> +    N / (SN0 * SN0), N / (SN0 * SN2), N / (SN0 * SN0), N / (SN0 * SN2),
> +    N / (SN2 * SN0), N / (SN2 * SN2), N / (SN2 * SN0), N / (SN2 * SN2),
> +    N / (SN0 * SN0), N / (SN0 * SN2), N / (SN0 * SN0), N / (SN0 * SN2),
> +    N / (SN2 * SN0), N / (SN2 * SN2), N / (SN2 * SN0), N / (SN2 *
> SN2),
> +};

probably it's better if you move the defines here, if they're not used
in the X86 code.

[...]
> +static inline int norm_qscale(int qscale, int type)
> +{
> +    switch (type) {
> +    case FF_QSCALE_TYPE_MPEG1: return qscale;
> +    case FF_QSCALE_TYPE_MPEG2: return qscale >> 1;
> +    case FF_QSCALE_TYPE_H264:  return qscale >> 2;
> +    case FF_QSCALE_TYPE_VP56:  return (63 - qscale + 2) >> 2;
> +    }
> +    return qscale;
> +}

Note: this could be moved to internal.h (ff_norm_qscale) and shared.

[...]
> +static int query_formats(AVFilterContext *ctx)
> +{
> +    static const enum PixelFormat pix_fmts[] = {
> +        AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV422P,
> +        AV_PIX_FMT_YUV420P,  AV_PIX_FMT_YUV411P,
> +        AV_PIX_FMT_YUV410P,  AV_PIX_FMT_YUV440P,
> +        AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ422P,
> +        AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ440P,
> +        AV_PIX_FMT_NONE
> +    };
> +    ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
> +    return 0;
> +}

Check that these are supported. Also the original is supporting some
more formats (for example GRAY8 == Y8).

[...]
> diff --git a/libavfilter/vf_pp7.h b/libavfilter/vf_pp7.h
> new file mode 100644
> index 0000000..1962bfa
> --- /dev/null
> +++ b/libavfilter/vf_pp7.h
> @@ -0,0 +1,57 @@
[...]
> +#ifndef AVFILTER_PP7_H
> +#define AVFILTER_PP7_H
> +
> +#include "avfilter.h"
> +

> +#define N0 4
> +#define N1 5
> +#define N2 10
> +#define SN0 2
> +#define SN1 2.2360679775
> +#define SN2 3.16227766017
> +#define N (1 << 16)

Move these defines close to the point we're they're used.

[...]
-- 
FFmpeg = Fantastic Fancy Mastodontic Philosofic Experimenting God


More information about the ffmpeg-devel mailing list