From patchwork Mon Dec 14 14:07:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 24566 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id ADA6E44A3B7 for ; Mon, 14 Dec 2020 16:08:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9962168A922; Mon, 14 Dec 2020 16:08:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C425C68A33F for ; Mon, 14 Dec 2020 16:08:07 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id C4DA3296DE4 for ; Mon, 14 Dec 2020 15:08:02 +0100 (CET) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id n105P_tbF0Bi for ; Mon, 14 Dec 2020 15:08:02 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id EA05C296DE1 for ; Mon, 14 Dec 2020 15:07:58 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 388D63A00EA; Mon, 14 Dec 2020 15:07:55 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Dec 2020 15:07:09 +0100 Message-Id: <20201214140716.12227-2-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201214140716.12227-1-anton@khirnov.net> References: <20201214140716.12227-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/9] lavfi/vf_qp: convert to the video_enc_params API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Temporarily disable fate-filter-qp until vf_pp is converted. --- libavfilter/vf_qp.c | 65 ++++++++++++++++++++++++------------- tests/fate/filter-video.mak | 8 ++--- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/libavfilter/vf_qp.c b/libavfilter/vf_qp.c index 33d39493bc..306e8e4594 100644 --- a/libavfilter/vf_qp.c +++ b/libavfilter/vf_qp.c @@ -23,6 +23,8 @@ #include "libavutil/imgutils.h" #include "libavutil/pixdesc.h" #include "libavutil/opt.h" +#include "libavutil/video_enc_params.h" + #include "avfilter.h" #include "formats.h" #include "internal.h" @@ -89,38 +91,59 @@ 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; + int ret; + + AVFrameSideData *sd_in; + AVVideoEncParams *par_in = NULL; + int8_t in_qp_global = 0; + + AVVideoEncParams *par_out; 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; + sd_in = av_frame_get_side_data(in, AV_FRAME_DATA_VIDEO_ENC_PARAMS); + if (sd_in && sd_in->size >= sizeof(AVVideoEncParams)) { + par_in = (AVVideoEncParams*)sd_in->data; + + // we accept the input QP table only if it is of the MPEG2 type + // and contains either no blocks at all or 16x16 macroblocks + if (par_in->type == AV_VIDEO_ENC_PARAMS_MPEG2 && + (par_in->nb_blocks == s->h * s->qstride || !par_in->nb_blocks)) { + in_qp_global = par_in->qp; + if (!par_in->nb_blocks) + par_in = NULL; + } else + par_in = NULL; } 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); + par_out = av_video_enc_params_create_side_data(out, AV_VIDEO_ENC_PARAMS_MPEG2, + (s->evaluate_per_mb || sd_in) ? + s->h * s->qstride : 0); + if (!par_out) { + ret = AVERROR(ENOMEM); + goto fail; + } +#define BLOCK_QP_DELTA(block_idx) \ + (par_in ? av_video_enc_params_block(par_in, block_idx)->delta_qp : 0) 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}; + unsigned int block_idx = y * s->qstride + x; + AVVideoBlockParams *b = av_video_enc_params_block(par_out, block_idx); + int qp = sd_in ? in_qp_global + BLOCK_QP_DELTA(block_idx) : NAN; + double var_values[] = { !!sd_in, qp, x, y, s->qstride, s->h, 0}; static const char *var_names[] = { "known", "qp", "x", "y", "w", "h", NULL }; double temp_val; @@ -129,21 +152,19 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) NULL, NULL, NULL, NULL, 0, 0, ctx); if (ret < 0) goto fail; - out_qp_table_buf->data[x + s->qstride * y] = lrintf(temp_val); + b->delta_qp = lrintf(temp_val); } - } else if (in_qp_table) { + } else if (sd_in) { 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])]; + for (x = 0; x < s->qstride; x++) { + unsigned int block_idx = y * s->qstride + x; + AVVideoBlockParams *b = av_video_enc_params_block(par_out, block_idx); + b->delta_qp = s->lut[129 + (int8_t)(in_qp_global + BLOCK_QP_DELTA(block_idx))]; + } } 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; + par_out->qp = s->lut[0]; } ret = ff_filter_frame(outlink, out); diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 34cfc38aba..7f5c07fd24 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -567,8 +567,8 @@ $(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-pp2: CMD = video_filter "qp=2*(x+y),pp=be/h1/v1/lb" +fate-filter-pp3: CMD = video_filter "qp=2*(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" @@ -585,8 +585,8 @@ FATE_FILTER_VSYNTH-$(CONFIG_CODECVIEW_FILTER) += fate-filter-codecview fate-filter-codecview: fate-vsynth1-mpeg4-qprd fate-filter-codecview: CMD = framecrc -flags bitexact -idct simple -flags2 +export_mvs -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf codecview=mv=pf+bf+bb -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-$(call ALLYES, QP_FILTER PP_FILTER) += fate-filter-qp +fate-filter-qp: CMD = video_filter "qp=34,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