[FFmpeg-devel] [PATCH 03/12] lavfi: drop vf_qp

Paul B Mahol onemda at gmail.com
Mon Feb 24 14:56:56 EET 2020


Filter should not be removed, it should use qp via frame side data.

On 2/24/20, Anton Khirnov <anton at khirnov.net> wrote:
> It fundamentally depends on an API that has been deprecated for five
> years, has seen no commits since that time and is of highly dubious
> usefulness.
> ---
>  doc/filters.texi            |  32 -------
>  libavfilter/Makefile        |   1 -
>  libavfilter/allfilters.c    |   1 -
>  libavfilter/vf_qp.c         | 183 ------------------------------------
>  tests/fate/filter-video.mak |   7 +-
>  tests/ref/fate/filter-pp2   |   1 -
>  tests/ref/fate/filter-pp3   |   1 -
>  7 files changed, 1 insertion(+), 225 deletions(-)
>  delete mode 100644 libavfilter/vf_qp.c
>  delete mode 100644 tests/ref/fate/filter-pp2
>  delete mode 100644 tests/ref/fate/filter-pp3
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 70fd7a4cc7..2a1235183f 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -15335,38 +15335,6 @@ telecine NTSC input:
>  ffmpeg -i input -vf pullup -r 24000/1001 ...
>  @end example
>
> - at section qp
> -
> -Change video quantization parameters (QP).
> -
> -The filter accepts the following option:
> -
> - at table @option
> - at item qp
> -Set expression for quantization parameter.
> - at end table
> -
> -The expression is evaluated through the eval API and can contain, among
> others,
> -the following constants:
> -
> - at table @var
> - at item known
> -1 if index is not 129, 0 otherwise.
> -
> - at item qp
> -Sequential index starting from -129 to 128.
> - at end table
> -
> - at subsection Examples
> -
> - at itemize
> - at item
> -Some equation like:
> - at example
> -qp=2+2*sin(PI*qp)
> - at end example
> - at end itemize
> -
>  @section random
>
>  Flush video frames from internal cache of frames into a random order.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 089880a39d..74968b32e1 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -349,7 +349,6 @@ OBJS-$(CONFIG_PROGRAM_OPENCL_FILTER)         +=
> vf_program_opencl.o opencl.o fra
>  OBJS-$(CONFIG_PSEUDOCOLOR_FILTER)            += vf_pseudocolor.o
>  OBJS-$(CONFIG_PSNR_FILTER)                   += vf_psnr.o framesync.o
>  OBJS-$(CONFIG_PULLUP_FILTER)                 += vf_pullup.o
> -OBJS-$(CONFIG_QP_FILTER)                     += vf_qp.o
>  OBJS-$(CONFIG_RANDOM_FILTER)                 += vf_random.o
>  OBJS-$(CONFIG_READEIA608_FILTER)             += vf_readeia608.o
>  OBJS-$(CONFIG_READVITC_FILTER)               += vf_readvitc.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 88ebd121ad..aa6f006ddb 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -332,7 +332,6 @@ extern AVFilter ff_vf_program_opencl;
>  extern AVFilter ff_vf_pseudocolor;
>  extern AVFilter ff_vf_psnr;
>  extern AVFilter ff_vf_pullup;
> -extern AVFilter ff_vf_qp;
>  extern AVFilter ff_vf_random;
>  extern AVFilter ff_vf_readeia608;
>  extern AVFilter ff_vf_readvitc;
> diff --git a/libavfilter/vf_qp.c b/libavfilter/vf_qp.c
> deleted file mode 100644
> index 33d39493bc..0000000000
> --- a/libavfilter/vf_qp.c
> +++ /dev/null
> @@ -1,183 +0,0 @@
> -/*
> - * Copyright (C) 2004 Michael Niedermayer <michaelni at gmx.at>
> - *
> - * This file is part of FFmpeg.
> - *
> - * FFmpeg is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU Lesser General Public
> - * License as published by the Free Software Foundation; either
> - * version 2.1 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
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser 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
> - */
> -
> -#include <math.h>
> -#include "libavutil/eval.h"
> -#include "libavutil/imgutils.h"
> -#include "libavutil/pixdesc.h"
> -#include "libavutil/opt.h"
> -#include "avfilter.h"
> -#include "formats.h"
> -#include "internal.h"
> -#include "video.h"
> -
> -typedef struct QPContext {
> -    const AVClass *class;
> -    char *qp_expr_str;
> -    int8_t lut[257];
> -    int h, qstride;
> -    int evaluate_per_mb;
> -} QPContext;
> -
> -#define OFFSET(x) offsetof(QPContext, x)
> -#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> -
> -static const AVOption qp_options[] = {
> -    { "qp", "set qp expression", OFFSET(qp_expr_str), AV_OPT_TYPE_STRING,
> {.str=NULL}, 0, 0, FLAGS },
> -    { NULL }
> -};
> -
> -AVFILTER_DEFINE_CLASS(qp);
> -
> -static int config_input(AVFilterLink *inlink)
> -{
> -    AVFilterContext *ctx = inlink->dst;
> -    QPContext *s = ctx->priv;
> -    int i;
> -    int ret;
> -    AVExpr *e = NULL;
> -    static const char *var_names[] = { "known", "qp", "x", "y", "w", "h",
> NULL };
> -
> -    if (!s->qp_expr_str)
> -        return 0;
> -
> -    ret = av_expr_parse(&e, s->qp_expr_str, var_names, NULL, NULL, NULL,
> NULL, 0, ctx);
> -    if (ret < 0)
> -        return ret;
> -
> -    s->h       = (inlink->h + 15) >> 4;
> -    s->qstride = (inlink->w + 15) >> 4;
> -    for (i = -129; i < 128; i++) {
> -        double var_values[] = { i != -129, i, NAN, NAN, s->qstride, s->h,
> 0};
> -        double temp_val = av_expr_eval(e, var_values, NULL);
> -
> -        if (isnan(temp_val)) {
> -            if(strchr(s->qp_expr_str, 'x') || strchr(s->qp_expr_str, 'y'))
> -                s->evaluate_per_mb = 1;
> -            else {
> -                av_expr_free(e);
> -                return AVERROR(EINVAL);
> -            }
> -        }
> -
> -        s->lut[i + 129] = lrintf(temp_val);
> -    }
> -    av_expr_free(e);
> -
> -    return 0;
> -}
> -
> -static int filter_frame(AVFilterLink *inlink, AVFrame *in)
> -{
> -    AVFilterContext *ctx = inlink->dst;
> -    AVFilterLink *outlink = ctx->outputs[0];
> -    QPContext *s = ctx->priv;
> -    AVBufferRef *out_qp_table_buf;
> -    AVFrame *out = NULL;
> -    const int8_t *in_qp_table;
> -    int type, stride, ret;
> -
> -    if (!s->qp_expr_str || ctx->is_disabled)
> -        return ff_filter_frame(outlink, in);
> -
> -    out_qp_table_buf = av_buffer_alloc(s->h * s->qstride);
> -    if (!out_qp_table_buf) {
> -        ret = AVERROR(ENOMEM);
> -        goto fail;
> -    }
> -
> -    out = av_frame_clone(in);
> -    if (!out) {
> -        av_buffer_unref(&out_qp_table_buf);
> -        ret = AVERROR(ENOMEM);
> -        goto fail;
> -    }
> -
> -    in_qp_table = av_frame_get_qp_table(in, &stride, &type);
> -    av_frame_set_qp_table(out, out_qp_table_buf, s->qstride, type);
> -
> -
> -    if (s->evaluate_per_mb) {
> -        int y, x;
> -
> -        for (y = 0; y < s->h; y++)
> -            for (x = 0; x < s->qstride; x++) {
> -                int qp = in_qp_table ? in_qp_table[x + stride * y] : NAN;
> -                double var_values[] = { !!in_qp_table, qp, x, y,
> s->qstride, s->h, 0};
> -                static const char *var_names[] = { "known", "qp", "x", "y",
> "w", "h", NULL };
> -                double temp_val;
> -
> -                ret = av_expr_parse_and_eval(&temp_val, s->qp_expr_str,
> -                                            var_names, var_values,
> -                                            NULL, NULL, NULL, NULL, 0, 0,
> ctx);
> -                if (ret < 0)
> -                    goto fail;
> -                out_qp_table_buf->data[x + s->qstride * y] =
> lrintf(temp_val);
> -            }
> -    } else if (in_qp_table) {
> -        int y, x;
> -
> -        for (y = 0; y < s->h; y++)
> -            for (x = 0; x < s->qstride; x++)
> -                out_qp_table_buf->data[x + s->qstride * y] = s->lut[129 +
> -                    ((int8_t)in_qp_table[x + stride * y])];
> -    } else {
> -        int y, x, qp = s->lut[0];
> -
> -        for (y = 0; y < s->h; y++)
> -            for (x = 0; x < s->qstride; x++)
> -                out_qp_table_buf->data[x + s->qstride * y] = qp;
> -    }
> -
> -    ret = ff_filter_frame(outlink, out);
> -    out = NULL;
> -fail:
> -    av_frame_free(&in);
> -    av_frame_free(&out);
> -    return ret;
> -}
> -
> -static const AVFilterPad qp_inputs[] = {
> -    {
> -        .name         = "default",
> -        .type         = AVMEDIA_TYPE_VIDEO,
> -        .filter_frame = filter_frame,
> -        .config_props = config_input,
> -    },
> -    { NULL }
> -};
> -
> -static const AVFilterPad qp_outputs[] = {
> -    {
> -        .name = "default",
> -        .type = AVMEDIA_TYPE_VIDEO,
> -    },
> -    { NULL }
> -};
> -
> -AVFilter ff_vf_qp = {
> -    .name          = "qp",
> -    .description   = NULL_IF_CONFIG_SMALL("Change video quantization
> parameters."),
> -    .priv_size     = sizeof(QPContext),
> -    .inputs        = qp_inputs,
> -    .outputs       = qp_outputs,
> -    .priv_class    = &qp_class,
> -    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
> -};
> diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak
> index 2da27f714a..5f4fd75b40 100644
> --- a/tests/fate/filter-video.mak
> +++ b/tests/fate/filter-video.mak
> @@ -531,21 +531,16 @@ fate-filter-idet: CMD = framecrc -flags bitexact -idct
> simple -i $(SRC) -vf idet
>  FATE_FILTER_VSYNTH-$(CONFIG_PAD_FILTER) += fate-filter-pad
>  fate-filter-pad: CMD = video_filter "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2"
>
> -FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 fate-filter-pp2
> fate-filter-pp3 fate-filter-pp4 fate-filter-pp5 fate-filter-pp6
> +FATE_FILTER_PP = fate-filter-pp fate-filter-pp1 fate-filter-pp4
> fate-filter-pp5 fate-filter-pp6
>  FATE_FILTER_VSYNTH-$(CONFIG_PP_FILTER) += $(FATE_FILTER_PP)
>  $(FATE_FILTER_PP): fate-vsynth1-mpeg4-qprd
>
>  fate-filter-pp:  CMD = framecrc -flags bitexact -idct simple -i
> $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags
> +bitexact -vf "pp=be/hb/vb/tn/l5/al"
>  fate-filter-pp1: CMD = video_filter "pp=fq|4/be/hb/vb/tn/l5/al"
> -fate-filter-pp2: CMD = video_filter "qp=x+y,pp=be/h1/v1/lb"
> -fate-filter-pp3: CMD = video_filter "qp=x+y,pp=be/ha|128|7/va/li"
>  fate-filter-pp4: CMD = video_filter "pp=be/ci"
>  fate-filter-pp5: CMD = video_filter "pp=md"
>  fate-filter-pp6: CMD = video_filter "pp=be/fd"
>
> -FATE_FILTER_VSYNTH-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp
> -fate-filter-qp: CMD = video_filter "qp=17,pp=be/hb/vb/tn/l5/al"
> -
>  FATE_FILTER_VSYNTH-$(CONFIG_SELECT_FILTER) += fate-filter-select
>  fate-filter-select: CMD = framecrc -flags bitexact -idct simple -i $(SRC)
> -vf "select=not(eq(mod(n\,2)\,0)+eq(mod(n\,3)\,0))" -frames:v 25 -flags
> +bitexact
>
> diff --git a/tests/ref/fate/filter-pp2 b/tests/ref/fate/filter-pp2
> deleted file mode 100644
> index ed5e77322a..0000000000
> --- a/tests/ref/fate/filter-pp2
> +++ /dev/null
> @@ -1 +0,0 @@
> -pp2                 566d48ad25dfa7a9680de933cbdf66d9
> diff --git a/tests/ref/fate/filter-pp3 b/tests/ref/fate/filter-pp3
> deleted file mode 100644
> index 536bf8e9d2..0000000000
> --- a/tests/ref/fate/filter-pp3
> +++ /dev/null
> @@ -1 +0,0 @@
> -pp3                 586fc14a52699540a865c070dd113229
> --
> 2.24.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list