From patchwork Fri Oct 2 18:03:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22690 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 8436444A33C for ; Fri, 2 Oct 2020 21:03:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F23868A107; Fri, 2 Oct 2020 21:03:56 +0300 (EEST) 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 83692688265 for ; Fri, 2 Oct 2020 21:03:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id D4C91296119 for ; Fri, 2 Oct 2020 20:03:48 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pMm-ECjLlFim for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 5C78E296113 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 626DD20E00BD; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:25 +0200 Message-Id: <20201002180331.20416-1-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] mpegvideo: use the AVVideoEncParams API for exporting QP tables 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" Do it only when requested with the AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS flag. Drop previous code using the long-deprecated AV_FRAME_DATA_QP_TABLE* API. Temporarily disable fate-filter-pp, fate-filter-pp7, fate-filter-spp. They will be reenabled once these filters are converted in following commits. --- doc/APIchanges | 3 +++ libavcodec/h263dec.c | 2 ++ libavcodec/mpeg12dec.c | 1 + libavcodec/mpegpicture.c | 2 ++ libavcodec/mpegpicture.h | 1 + libavcodec/mpegvideo.c | 35 ++++++++++++++++++++++++++++------- libavcodec/rv34.c | 1 + libavutil/version.h | 2 +- libavutil/video_enc_params.h | 8 ++++++++ tests/fate/filter-video.mak | 6 +++--- 10 files changed, 50 insertions(+), 11 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index f2830968bb..97a0f92dca 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2020-xx-xx - xxxxxxxxxx - lavu 56.61.100 - video_enc_params.h + Add AV_VIDEO_ENC_PARAMS_MPEG2 + 2020-xx-xx - xxxxxxxxxx - lavu 56.60.100 - buffer.h Add a av_buffer_replace() convenience function. diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 3b29a189e9..f6b6c33109 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -28,6 +28,8 @@ #define UNCHECKED_BITSTREAM_READER 1 #include "libavutil/cpu.h" +#include "libavutil/video_enc_params.h" + #include "avcodec.h" #include "error_resilience.h" #include "flv.h" diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 2494226aa3..d380b376a6 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -32,6 +32,7 @@ #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/stereo3d.h" +#include "libavutil/video_enc_params.h" #include "avcodec.h" #include "bytestream.h" diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 13c11ec492..e495e315e6 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -220,6 +220,7 @@ static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encodin pic->alloc_mb_width = mb_width; pic->alloc_mb_height = mb_height; + pic->alloc_mb_stride = mb_stride; return 0; } @@ -346,6 +347,7 @@ int ff_update_picture_tables(Picture *dst, Picture *src) dst->alloc_mb_width = src->alloc_mb_width; dst->alloc_mb_height = src->alloc_mb_height; + dst->alloc_mb_stride = src->alloc_mb_stride; return 0; } diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index 2db3d6733a..4bcd666797 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -69,6 +69,7 @@ typedef struct Picture { int alloc_mb_width; ///< mb_width used to allocate tables int alloc_mb_height; ///< mb_height used to allocate tables + int alloc_mb_stride; ///< mb_stride used to allocate tables AVBufferRef *mb_mean_buf; uint8_t *mb_mean; ///< Table for MB luminance diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index c28d1adef7..8cc21920e6 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -32,6 +32,8 @@ #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/motion_vector.h" +#include "libavutil/video_enc_params.h" + #include "avcodec.h" #include "blockdsp.h" #include "h264chroma.h" @@ -1425,14 +1427,33 @@ void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict) int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type) { - AVBufferRef *ref = av_buffer_ref(p->qscale_table_buf); - int offset = 2*s->mb_stride + 1; - if(!ref) + AVVideoEncParams *par; + int mult = (qp_type == FF_QSCALE_TYPE_MPEG1) ? 2 : 1; + unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width; + unsigned int x, y; + + if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS)) + return 0; + + par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb); + if (!par) return AVERROR(ENOMEM); - av_assert0(ref->size >= offset + s->mb_stride * ((f->height+15)/16)); - ref->size -= offset; - ref->data += offset; - return av_frame_set_qp_table(f, ref, s->mb_stride, qp_type); + + for (y = 0; y < p->alloc_mb_height; y++) + for (x = 0; x < p->alloc_mb_width; x++) { + const unsigned int block_idx = y * p->alloc_mb_width + x; + const unsigned int mb_xy = y * p->alloc_mb_stride + x; + AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx); + + b->src_x = x * 16; + b->src_y = y * 16; + b->w = 16; + b->h = 16; + + b->delta_qp = p->qscale_table[mb_xy] * mult; + } + + return 0; } static inline int hpel_motion_lowres(MpegEncContext *s, diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index ec0cd27916..44d9581ac9 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -26,6 +26,7 @@ #include "libavutil/imgutils.h" #include "libavutil/internal.h" +#include "libavutil/video_enc_params.h" #include "avcodec.h" #include "error_resilience.h" diff --git a/libavutil/version.h b/libavutil/version.h index 1aca823650..55a59d6c58 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 60 +#define LIBAVUTIL_VERSION_MINOR 61 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h index e3b422d6f3..fc0c3bc1a5 100644 --- a/libavutil/video_enc_params.h +++ b/libavutil/video_enc_params.h @@ -55,6 +55,14 @@ enum AVVideoEncParamsType { * as AVVideoBlockParams.qp_delta. */ AV_VIDEO_ENC_PARAMS_H264, + + /* + * MPEG-2-compatible quantizer. + * + * Summing the frame-level qp with the per-block delta_qp gives the + * resulting quantizer for the block. + */ + AV_VIDEO_ENC_PARAMS_MPEG2, }; /** diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 639f957748..900e43ac68 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -558,7 +558,7 @@ 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-pp2 fate-filter-pp3 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 @@ -570,11 +570,11 @@ 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-$(CONFIG_PP7_FILTER) += fate-filter-pp7 +#FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7 fate-filter-pp7: fate-vsynth1-mpeg4-qprd fate-filter-pp7: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp7" -FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp +#FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp fate-filter-spp: fate-vsynth1-mpeg4-qprd fate-filter-spp: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "spp=idct=simple:dct=int" From patchwork Fri Oct 2 18:03:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22693 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 08F0B44A33C for ; Fri, 2 Oct 2020 21:04:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D065668A800; Fri, 2 Oct 2020 21:04:00 +0300 (EEST) 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 C8226688265 for ; Fri, 2 Oct 2020 21:03:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 5DFF1296113 for ; Fri, 2 Oct 2020 20:03:50 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id lAXanYvkulp1 for ; Fri, 2 Oct 2020 20:03:49 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 55C512960FB for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 9DA0A20E00BF; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:26 +0200 Message-Id: <20201002180331.20416-2-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] 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 900e43ac68..b611dccf24 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -564,8 +564,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" @@ -582,8 +582,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 From patchwork Fri Oct 2 18:03:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22696 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1481830ybf; Fri, 2 Oct 2020 11:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4KCezikThIFhwRKxe66eYtpSTBxMsp7dUXuM49z4tY4/TKfABtSa2YmwOj2v05VmYUccZ X-Received: by 2002:a05:600c:4104:: with SMTP id j4mr4072952wmi.36.1601661890153; Fri, 02 Oct 2020 11:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601661890; cv=none; d=google.com; s=arc-20160816; b=aG+YwBMI0wTbg46CtAVPFN67aZM0Cf/Nr5DV9UvDWayV1SOL3TUPRVhlXdnzksAmSX tKiB1a98nwq+Lm53jYHKl/l5QgMkAi+s0eb6Qux3KyODHiSfMu2XZN8seQzGEvSwI3fR 0VVv6fvlC79et6mRezRqjB82NCcR9y60vACBhbsQKovv0UAGne7sxJ4k62DZj01HSg/h XOWlabt9qoS/V5sWpkWZgD+OJ+28vkNcH0N11980emvwmum/78jiS05WvIv665keevoz cunXnZ/TZsCczkhjhn4tHMCl0wDH7BSJf0PHr1/YS8Y3U/sV2o97dGauUF5nv4NKaHjf EIIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=tJ3HSnoLihyWU6Z7G/x37ZfEk/0B/99afvkoIPh4oDA=; b=HzydWoWsRpn9TKOWIUvnDtHiwxL8r1PT3TVCN/u8ZO/KJl4+EPKHjxAZJZcjj/0QQ1 7w92PXs2q2uS9F37KD/uJCNj1Xemkl0Ri3jDDI33C8DwQqUjNKznZ/dWxwltLRb8Ly2w BkDeY6TE4cYlbA5AZsEw5phUA66ndOOOc2FHqoD4XaoL6V7Yek15BJmDAraIwJ5xcsgD 7kdclsDjnHMgY+g5uYxDJMkdB1BtP+jgUgkoicv/WwKSMbsP8Rz0uZMwYvp5WSpFTd4q ev0UEE1/+3SQOwd+Qo4fItVcTWZqBIHZfkt+a2KaTlL0HGvrmrP7cepEeUlWg29KZiA/ +cRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l8si2112101wrp.137.2020.10.02.11.04.49; Fri, 02 Oct 2020 11:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 88D74688179; Fri, 2 Oct 2020 21:04:02 +0300 (EEST) 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 0764D689D06 for ; Fri, 2 Oct 2020 21:03:52 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 9DF51296114 for ; Fri, 2 Oct 2020 20:03:51 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6m-Xj-0NKwTw for ; Fri, 2 Oct 2020 20:03:50 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 66BC0296115 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id BE56F20E008E; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:27 +0200 Message-Id: <20201002180331.20416-3-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] lavfi/vf_pp: 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" X-TUID: oFtn2QFE8Ldw Content-Length: 11656 --- libavfilter/Makefile | 2 +- libavfilter/qp_table.c | 66 +++++++++++++++++++++++++++++++++++++ libavfilter/qp_table.h | 32 ++++++++++++++++++ libavfilter/vf_pp.c | 19 ++++++++--- tests/fate/filter-video.mak | 6 ++-- 5 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 libavfilter/qp_table.c create mode 100644 libavfilter/qp_table.h diff --git a/libavfilter/Makefile b/libavfilter/Makefile index e6d3c283da..d20f2937b6 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -344,7 +344,7 @@ OBJS-$(CONFIG_PHASE_FILTER) += vf_phase.o OBJS-$(CONFIG_PHOTOSENSITIVITY_FILTER) += vf_photosensitivity.o OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o OBJS-$(CONFIG_PIXSCOPE_FILTER) += vf_datascope.o -OBJS-$(CONFIG_PP_FILTER) += vf_pp.o +OBJS-$(CONFIG_PP_FILTER) += vf_pp.o qp_table.o OBJS-$(CONFIG_PP7_FILTER) += vf_pp7.o OBJS-$(CONFIG_PREMULTIPLY_FILTER) += vf_premultiply.o framesync.o OBJS-$(CONFIG_PREWITT_FILTER) += vf_convolution.o diff --git a/libavfilter/qp_table.c b/libavfilter/qp_table.c new file mode 100644 index 0000000000..df75c6371d --- /dev/null +++ b/libavfilter/qp_table.c @@ -0,0 +1,66 @@ +/* + * 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. + */ + +#include + +#include "libavutil/frame.h" +#include "libavutil/mem.h" +#include "libavutil/video_enc_params.h" + +#include "qp_table.h" + +int ff_qp_table_extract(AVFrame *frame, int8_t **table, int *table_w, int *table_h) +{ + AVFrameSideData *sd; + AVVideoEncParams *par; + unsigned int mb_h = (frame->height + 15) / 16; + unsigned int mb_w = (frame->width + 15) / 16; + unsigned int nb_mb = mb_h * mb_w; + unsigned int block_idx; + + *table = NULL; + + sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS); + if (!sd) + return 0; + par = (AVVideoEncParams*)sd->data; + if (par->type != AV_VIDEO_ENC_PARAMS_MPEG2 || + (par->nb_blocks != 0 && par->nb_blocks != nb_mb)) + return 0; + + *table = av_malloc(nb_mb); + if (!*table) + return AVERROR(ENOMEM); + if (table_w) + *table_w = mb_w; + if (table_h) + *table_h = mb_h; + + if (par->nb_blocks == 0) { + memset(*table, par->qp, nb_mb); + return 0; + } + + for (block_idx = 0; block_idx < nb_mb; block_idx++) { + AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx); + (*table)[block_idx] = par->qp + b->delta_qp; + } + + return 0; +} + diff --git a/libavfilter/qp_table.h b/libavfilter/qp_table.h new file mode 100644 index 0000000000..5a9ec889b6 --- /dev/null +++ b/libavfilter/qp_table.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#ifndef AVFILTER_QP_TABLE_H +#define AVFILTER_QP_TABLE_H + +#include + +#include "libavutil/frame.h" + +/** + * Extract a "classic" libpostproc-style QP table from AVVideoEncParams side + * data. + */ +int ff_qp_table_extract(AVFrame *frame, int8_t **table, int *table_w, int *table_h); + +#endif // AVFILTER_QP_TABLE_H diff --git a/libavfilter/vf_pp.c b/libavfilter/vf_pp.c index 524ef1bb0a..4471925f7b 100644 --- a/libavfilter/vf_pp.c +++ b/libavfilter/vf_pp.c @@ -26,7 +26,9 @@ #include "libavutil/avassert.h" #include "libavutil/opt.h" + #include "internal.h" +#include "qp_table.h" #include "libpostproc/postprocess.h" @@ -126,8 +128,9 @@ static int pp_filter_frame(AVFilterLink *inlink, AVFrame *inbuf) const int aligned_w = FFALIGN(outlink->w, 8); const int aligned_h = FFALIGN(outlink->h, 8); AVFrame *outbuf; - int qstride, qp_type; - int8_t *qp_table ; + int qstride = 0; + int8_t *qp_table = NULL; + int ret; outbuf = ff_get_video_buffer(outlink, aligned_w, aligned_h); if (!outbuf) { @@ -137,7 +140,14 @@ static int pp_filter_frame(AVFilterLink *inlink, AVFrame *inbuf) av_frame_copy_props(outbuf, inbuf); outbuf->width = inbuf->width; outbuf->height = inbuf->height; - qp_table = av_frame_get_qp_table(inbuf, &qstride, &qp_type); + + ret = ff_qp_table_extract(inbuf, &qp_table, &qstride, NULL); + if (ret < 0) { + av_frame_free(&inbuf); + av_frame_free(&outbuf); + av_freep(&qp_table); + return ret; + } pp_postprocess((const uint8_t **)inbuf->data, inbuf->linesize, outbuf->data, outbuf->linesize, @@ -146,9 +156,10 @@ static int pp_filter_frame(AVFilterLink *inlink, AVFrame *inbuf) qstride, pp->modes[pp->mode_id], pp->pp_ctx, - outbuf->pict_type | (qp_type ? PP_PICT_TYPE_QP2 : 0)); + outbuf->pict_type | (qp_table ? PP_PICT_TYPE_QP2 : 0)); av_frame_free(&inbuf); + av_freep(&qp_table); return ff_filter_frame(outlink, outbuf); } diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index b611dccf24..98df744f16 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -558,11 +558,11 @@ 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-pp2 fate-filter-pp3 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-pp: CMD = framecrc -flags bitexact -export_side_data venc_params -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=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" @@ -582,7 +582,7 @@ 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_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 From patchwork Fri Oct 2 18:03:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22691 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 C666544A33C for ; Fri, 2 Oct 2020 21:03:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACB9C68A1AE; Fri, 2 Oct 2020 21:03:57 +0300 (EEST) 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 91FC6689D06 for ; Fri, 2 Oct 2020 21:03:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id D2AEA296118 for ; Fri, 2 Oct 2020 20:03:48 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 5S4uHA_qCedK for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 57515296112 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 81C3F20E0088; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:28 +0200 Message-Id: <20201002180331.20416-4-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] lavfi/vf_spp: 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" --- libavfilter/Makefile | 2 +- libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- libavfilter/vf_spp.h | 3 +- tests/fate/filter-video.mak | 4 +-- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index d20f2937b6..2669d7b84b 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ opencl/convolution.o OBJS-$(CONFIG_SPLIT_FILTER) += split.o -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o OBJS-$(CONFIG_SR_FILTER) += vf_sr.o OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c index 4bcc6429e0..2eb383be03 100644 --- a/libavfilter/vf_spp.c +++ b/libavfilter/vf_spp.c @@ -36,6 +36,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "internal.h" +#include "qp_table.h" #include "vf_spp.h" enum mode { @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, } else{ const int qps = 3 + is_luma; qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); } for (i = 0; i < count; i++) { const int x1 = x + offset[i + count - 1][0]; @@ -374,47 +375,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out = in; int qp_stride = 0; - const int8_t *qp_table = NULL; + int8_t *qp_table = NULL; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); const int depth = desc->comp[0].depth; + int ret = 0; /* if we are not in a constant user quantizer mode and we don't want to use * the quantizers from the B-frames (B-frames often have a higher QP), we * need to save the qp table from the last non B-frame; this is what the * following code block does */ - if (!s->qp) { - qp_table = av_frame_get_qp_table(in, &qp_stride, &s->qscale_type); - - if (qp_table && !s->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { - int w, h; - - /* if the qp stride is not set, it means the QP are only defined on - * a line basis */ - if (!qp_stride) { - w = AV_CEIL_RSHIFT(inlink->w, 4); - h = 1; - } else { - w = qp_stride; - h = AV_CEIL_RSHIFT(inlink->h, 4); - } - - if (w * h > s->non_b_qp_alloc_size) { - int ret = av_reallocp_array(&s->non_b_qp_table, w, h); - if (ret < 0) { - s->non_b_qp_alloc_size = 0; - return ret; - } - s->non_b_qp_alloc_size = w * h; - } + if (!s->qp && (s->use_bframe_qp || in->pict_type != AV_PICTURE_TYPE_B)) { + ret = ff_qp_table_extract(in, &qp_table, &qp_stride, NULL); + if (ret < 0) { + av_frame_free(&in); + return ret; + } - av_assert0(w * h <= s->non_b_qp_alloc_size); - memcpy(s->non_b_qp_table, qp_table, w * h); + if (!s->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { + av_freep(&s->non_b_qp_table); + s->non_b_qp_table = qp_table; + s->non_b_qp_stride = qp_stride; } } if (s->log2_count && !ctx->is_disabled) { - if (!s->use_bframe_qp && s->non_b_qp_table) - qp_table = s->non_b_qp_table; + if (!s->use_bframe_qp && s->non_b_qp_table) { + qp_table = s->non_b_qp_table; + qp_stride = s->non_b_qp_stride; + } if (qp_table || s->qp) { const int cw = AV_CEIL_RSHIFT(inlink->w, s->hsub); @@ -429,7 +417,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out = ff_get_video_buffer(outlink, aligned_w, aligned_h); if (!out) { av_frame_free(&in); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto finish; } av_frame_copy_props(out, in); out->width = in->width; @@ -453,7 +442,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) inlink->w, inlink->h); av_frame_free(&in); } - return ff_filter_frame(outlink, out); + ret = ff_filter_frame(outlink, out); +finish: + if (qp_table != s->non_b_qp_table) + av_freep(&qp_table); + return ret; } static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, diff --git a/libavfilter/vf_spp.h b/libavfilter/vf_spp.h index 879ed40f03..00caf5780d 100644 --- a/libavfilter/vf_spp.h +++ b/libavfilter/vf_spp.h @@ -33,13 +33,12 @@ typedef struct SPPContext { int log2_count; int qp; int mode; - int qscale_type; int temp_linesize; uint8_t *src; uint16_t *temp; AVDCT *dct; int8_t *non_b_qp_table; - int non_b_qp_alloc_size; + int non_b_qp_stride; int use_bframe_qp; int hsub, vsub; diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 98df744f16..202c7f30d7 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -574,9 +574,9 @@ fate-filter-pp6: CMD = video_filter "pp=be/fd" fate-filter-pp7: fate-vsynth1-mpeg4-qprd fate-filter-pp7: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp7" -#FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp +FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp fate-filter-spp: fate-vsynth1-mpeg4-qprd -fate-filter-spp: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "spp=idct=simple:dct=int" +fate-filter-spp: CMD = framecrc -flags bitexact -export_side_data venc_params -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "spp=idct=simple:dct=int" FATE_FILTER_VSYNTH-$(CONFIG_CODECVIEW_FILTER) += fate-filter-codecview fate-filter-codecview: fate-vsynth1-mpeg4-qprd From patchwork Fri Oct 2 18:03:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22692 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 D4B4344A33C for ; Fri, 2 Oct 2020 21:03:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB56D68A494; Fri, 2 Oct 2020 21:03:59 +0300 (EEST) 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 BB24C688179 for ; Fri, 2 Oct 2020 21:03:50 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 5DFEB296112 for ; Fri, 2 Oct 2020 20:03:50 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id PaUT5bMHxxcS for ; Fri, 2 Oct 2020 20:03:49 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 63741296114 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id DF6C120E00BE; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:29 +0200 Message-Id: <20201002180331.20416-5-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] lavfi/vf_pp7: 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" --- libavfilter/Makefile | 2 +- libavfilter/vf_pp7.c | 14 +++++++++++--- libavfilter/vf_pp7.h | 1 - tests/fate/filter-video.mak | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 2669d7b84b..dcbb867265 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -345,7 +345,7 @@ OBJS-$(CONFIG_PHOTOSENSITIVITY_FILTER) += vf_photosensitivity.o OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o OBJS-$(CONFIG_PIXSCOPE_FILTER) += vf_datascope.o OBJS-$(CONFIG_PP_FILTER) += vf_pp.o qp_table.o -OBJS-$(CONFIG_PP7_FILTER) += vf_pp7.o +OBJS-$(CONFIG_PP7_FILTER) += vf_pp7.o qp_table.o OBJS-$(CONFIG_PREMULTIPLY_FILTER) += vf_premultiply.o framesync.o OBJS-$(CONFIG_PREWITT_FILTER) += vf_convolution.o OBJS-$(CONFIG_PREWITT_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ diff --git a/libavfilter/vf_pp7.c b/libavfilter/vf_pp7.c index 570a1c90b9..9e961fcd19 100644 --- a/libavfilter/vf_pp7.c +++ b/libavfilter/vf_pp7.c @@ -32,6 +32,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "internal.h" +#include "qp_table.h" #include "vf_pp7.h" enum mode { @@ -240,7 +241,7 @@ static void filter(PP7Context *p, uint8_t *dst, uint8_t *src, qp = p->qp; else { qp = qp_store[ (FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; - qp = ff_norm_qscale(qp, p->qscale_type); + qp = ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2); } for (; x < end; x++) { const int index = x + y * stride + (8 - 3) * (1 + stride) + 8; //FIXME silly offset @@ -324,8 +325,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) int qp_stride = 0; uint8_t *qp_table = NULL; - if (!pp7->qp) - qp_table = av_frame_get_qp_table(in, &qp_stride, &pp7->qscale_type); + if (!pp7->qp) { + int ret = ff_qp_table_extract(in, &qp_table, &qp_stride, NULL); + if (ret < 0) { + av_frame_free(&in); + return ret; + } + } if (!ctx->is_disabled) { const int cw = AV_CEIL_RSHIFT(inlink->w, pp7->hsub); @@ -340,6 +346,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out = ff_get_video_buffer(outlink, aligned_w, aligned_h); if (!out) { av_frame_free(&in); + av_freep(&qp_table); return AVERROR(ENOMEM); } av_frame_copy_props(out, in); @@ -366,6 +373,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) inlink->w, inlink->h); av_frame_free(&in); } + av_freep(&qp_table); return ff_filter_frame(outlink, out); } diff --git a/libavfilter/vf_pp7.h b/libavfilter/vf_pp7.h index 9aa8d732c1..8ec816b468 100644 --- a/libavfilter/vf_pp7.h +++ b/libavfilter/vf_pp7.h @@ -30,7 +30,6 @@ typedef struct PP7Context { int qp; int mode; - int qscale_type; int hsub; int vsub; int temp_stride; diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 202c7f30d7..8231752276 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -570,9 +570,9 @@ 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-$(CONFIG_PP7_FILTER) += fate-filter-pp7 +FATE_FILTER_VSYNTH-$(CONFIG_PP7_FILTER) += fate-filter-pp7 fate-filter-pp7: fate-vsynth1-mpeg4-qprd -fate-filter-pp7: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp7" +fate-filter-pp7: CMD = framecrc -flags bitexact -export_side_data venc_params -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp7" FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp fate-filter-spp: fate-vsynth1-mpeg4-qprd From patchwork Fri Oct 2 18:03:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22718 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1482046ybf; Fri, 2 Oct 2020 11:05:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMA66DpL/1DOEiQRdSD1waU5uh2dMD41xyi8aFScZEFFi8MJusFl8Jp22EpqVb5omccf0Z X-Received: by 2002:a7b:c183:: with SMTP id y3mr4186516wmi.84.1601661909482; Fri, 02 Oct 2020 11:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601661909; cv=none; d=google.com; s=arc-20160816; b=ZuHVYOLVcQaEmeBLIHNctBnsWT4ehWx2kFF4ywMgm+txm/yKF5yZW6oSPdPKY6AsFf 3gAydP56EK9Tt5AEn50I5N/AJGivXZb9RU6jU9nTN/sOfNfsxyAlSBO+C/NGFWVaWaUI uDX27A8qaTkBYXMzBkYAP8awmj3tnZHiOYkCOBvISsgKpAVAag/CuSzti6O/dsXqhIq0 tPiFgJNYJa4xUeOMrJtCDfDHVA1RwdlN/kO4mYKJs5Lup4bKPkm+BRqDP64FqWayaOtu KlphvGy6fegmderQiwVThjs+EkpNON1dEvKGvwwxBWA9dRHAFzXCEzvJ0IvX+i9Yve6F fV4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=u7eWRPnRJlB4xAQ7YmmHlrS7qMuQBq0dMZ1M6yO3yNo=; b=gmCCCrmrocp0AbbetGh9XqDYTkYsOhYreqOuByDnVKplg2qMZq7pfRaWiIulKKP1G/ b/bLU43dvqBk+0GatV341NTTqkKa3y09BTyF3kJCvchzOtUBiLbVVRhMUejFjVNP3TAT G/dPYYJbnwkcwutBAKChytl2skecBc4RnoKtb1O/M3jONwzfkuVMFyvtEojqyM/NfLaP ZCr3TQwdHcUO68yAVs+KYiAF+r4hvJrESJJJVpfDEgrrY6muIgQe5L5Upu9YtNEQHy9D zJiT7OJ4ZO6Vj9xk97HbU944dG9vS8GRBzzmmsywN4w4GgfI6i4baxcn87p3nSY6RvgO 1EtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a184si2164119wmd.103.2020.10.02.11.05.08; Fri, 02 Oct 2020 11:05:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C56F768AA60; Fri, 2 Oct 2020 21:04:03 +0300 (EEST) 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 DD85A68A0F0 for ; Fri, 2 Oct 2020 21:03:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 10BDE296115 for ; Fri, 2 Oct 2020 20:03:52 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id eU3b_kOy7kGE for ; Fri, 2 Oct 2020 20:03:51 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id BC007296116 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 08C9C20E00C0; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:30 +0200 Message-Id: <20201002180331.20416-6-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] lavfi/vf_fspp: 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" X-TUID: zjYnsLKfWm6c Content-Length: 8649 --- libavfilter/Makefile | 2 +- libavfilter/vf_fspp.c | 59 +++++++++++++++++-------------------------- libavfilter/vf_fspp.h | 2 +- 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index dcbb867265..be2c3e3156 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -263,7 +263,7 @@ OBJS-$(CONFIG_FRAMESTEP_FILTER) += vf_framestep.o OBJS-$(CONFIG_FREEZEDETECT_FILTER) += vf_freezedetect.o OBJS-$(CONFIG_FREEZEFRAMES_FILTER) += vf_freezeframes.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o -OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o +OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o qp_table.o OBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o OBJS-$(CONFIG_GEQ_FILTER) += vf_geq.o OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o diff --git a/libavfilter/vf_fspp.c b/libavfilter/vf_fspp.c index c6989046c4..cc743752d3 100644 --- a/libavfilter/vf_fspp.c +++ b/libavfilter/vf_fspp.c @@ -40,6 +40,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "internal.h" +#include "qp_table.h" #include "vf_fspp.h" #define OFFSET(x) offsetof(FSPPContext, x) @@ -206,7 +207,7 @@ static void filter(FSPPContext *p, uint8_t *dst, uint8_t *src, if (t < 0) t = 0; //t always < width-2 t = qp_store[qy + (t >> qpsh)]; - t = ff_norm_qscale(t, p->qscale_type); + t = ff_norm_qscale(t, FF_QSCALE_TYPE_MPEG2); if (t != p->prev_q) p->prev_q = t, p->mul_thrmat((int16_t *)(&p->threshold_mtx_noq[0]), (int16_t *)(&p->threshold_mtx[0]), t); p->column_fidct((int16_t *)(&p->threshold_mtx[0]), block + x * 8, block3 + x * 8, 8); //yes, this is a HOTSPOT @@ -525,13 +526,6 @@ static int config_input(AVFilterLink *inlink) if (!fspp->temp || !fspp->src) return AVERROR(ENOMEM); - if (!fspp->use_bframe_qp && !fspp->qp) { - fspp->non_b_qp_alloc_size = AV_CEIL_RSHIFT(inlink->w, 4) * AV_CEIL_RSHIFT(inlink->h, 4); - fspp->non_b_qp_table = av_calloc(fspp->non_b_qp_alloc_size, sizeof(*fspp->non_b_qp_table)); - if (!fspp->non_b_qp_table) - return AVERROR(ENOMEM); - } - fspp->store_slice = store_slice_c; fspp->store_slice2 = store_slice2_c; fspp->mul_thrmat = mul_thrmat_c; @@ -555,6 +549,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) int qp_stride = 0; uint8_t *qp_table = NULL; int i, bias; + int ret = 0; int custom_threshold_m[64]; bias = (1 << 4) + fspp->strength; @@ -581,38 +576,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) * the quantizers from the B-frames (B-frames often have a higher QP), we * need to save the qp table from the last non B-frame; this is what the * following code block does */ - if (!fspp->qp) { - qp_table = av_frame_get_qp_table(in, &qp_stride, &fspp->qscale_type); - - if (qp_table && !fspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { - int w, h; - - /* if the qp stride is not set, it means the QP are only defined on - * a line basis */ - if (!qp_stride) { - w = AV_CEIL_RSHIFT(inlink->w, 4); - h = 1; - } else { - w = qp_stride; - h = AV_CEIL_RSHIFT(inlink->h, 4); - } - if (w * h > fspp->non_b_qp_alloc_size) { - int ret = av_reallocp_array(&fspp->non_b_qp_table, w, h); - if (ret < 0) { - fspp->non_b_qp_alloc_size = 0; - return ret; - } - fspp->non_b_qp_alloc_size = w * h; - } + if (!fspp->qp && (fspp->use_bframe_qp || in->pict_type != AV_PICTURE_TYPE_B)) { + ret = ff_qp_table_extract(in, &qp_table, &qp_stride, NULL); + if (ret < 0) { + av_frame_free(&in); + return ret; + } - av_assert0(w * h <= fspp->non_b_qp_alloc_size); - memcpy(fspp->non_b_qp_table, qp_table, w * h); + if (!fspp->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { + av_freep(&fspp->non_b_qp_table); + fspp->non_b_qp_table = qp_table; + fspp->non_b_qp_stride = qp_stride; } } if (fspp->log2_count && !ctx->is_disabled) { - if (!fspp->use_bframe_qp && fspp->non_b_qp_table) + if (!fspp->use_bframe_qp && fspp->non_b_qp_table) { qp_table = fspp->non_b_qp_table; + qp_stride = fspp->non_b_qp_stride; + } if (qp_table || fspp->qp) { const int cw = AV_CEIL_RSHIFT(inlink->w, fspp->hsub); @@ -627,7 +609,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out = ff_get_video_buffer(outlink, aligned_w, aligned_h); if (!out) { av_frame_free(&in); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto finish; } av_frame_copy_props(out, in); out->width = in->width; @@ -651,7 +634,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) inlink->w, inlink->h); av_frame_free(&in); } - return ff_filter_frame(outlink, out); + ret = ff_filter_frame(outlink, out); +finish: + if (qp_table != fspp->non_b_qp_table) + av_freep(&qp_table); + return ret; } static av_cold void uninit(AVFilterContext *ctx) diff --git a/libavfilter/vf_fspp.h b/libavfilter/vf_fspp.h index 73d8c7c771..6529f678ea 100644 --- a/libavfilter/vf_fspp.h +++ b/libavfilter/vf_fspp.h @@ -66,7 +66,7 @@ typedef struct FSPPContext { uint8_t *src; int16_t *temp; uint8_t *non_b_qp_table; - int non_b_qp_alloc_size; + int non_b_qp_stride; int use_bframe_qp; void (*store_slice)(uint8_t *dst, int16_t *src, From patchwork Fri Oct 2 18:03:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 22714 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1481954ybf; Fri, 2 Oct 2020 11:05:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXgfVDK2phEPuqySPrRBdeJC5cPMa67AwcOi4Urt34QlwYDRJ7ReuPyZH8bY3OwiALSiAQ X-Received: by 2002:a1c:e045:: with SMTP id x66mr3334128wmg.104.1601661901137; Fri, 02 Oct 2020 11:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601661901; cv=none; d=google.com; s=arc-20160816; b=RfsfoRjr/Y9lh9vcPParsCgz0hSPfTLP2AEiYUFKh2TlQ7H53/mkRAtLRlH1YRDUCs cw6er5SZOOkWXXs+qUbSqy/CilzG8CzMg2L20fLoBgf/JnZJdhvhw+lSRB5qCCSuKJB+ taJmOF1rPVxCkhpR1wneJ0HwNze93AB2gk8FsU3d8xuTThbnCwJWwvLLbUkjewrHT84t 5yo4kBjlWJKOCpmEqtmC+Obbni++t4YEFYPZ91du79fEknCQuzh84/nVHUz2acxOxvef L5XvbIpb09mCNhR9gaEb72rB/Q6o5x6JVRGsY20pbkW9k44f8lpslLTDRsLnT3kHmVR7 OPMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=AXwvjus/OXR61Kl1BulmgtPLcUVfmIATSdnRUkvpxc4=; b=h95a5uVTR3G2feeUIPw2NLcJh3SS2hHd8hE3mlZMvkaGhuP0EoHozHAzQVwafxtNuD 6kuxq4LwlsElPMEcxuH53aiXp3y+06GbLOMVTkBCypODFk7rWe0U4Ma1+s5l03i983/E mEQvo6J8wMfY+vws0aWcPAtjTZy2sqzUq2ES+ZqA9r7tNf3Y4HGkTpKeXMXXCTSY65OD OHXVFg/UpS3zICNkdbmLN3rOEMU7pVsPYPOB8R7yqbVMS633ZoubS8tatHOftt0y9/R7 YP0vMgujATFYVL5fiQfmAhA2C/nohQ1VtghdTwc2CLbBpfm1ZxF9OJyBXwazhfgiyG5m yWpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o5si2553825wme.89.2020.10.02.11.05.00; Fri, 02 Oct 2020 11:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C0EC68A9E1; Fri, 2 Oct 2020 21:04:03 +0300 (EEST) 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 E2D8968A562 for ; Fri, 2 Oct 2020 21:03:54 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 9DF392960FB for ; Fri, 2 Oct 2020 20:03:51 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id UJL3Ud0StSdQ for ; Fri, 2 Oct 2020 20:03:50 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.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.daenerys.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id BC4D8296117 for ; Fri, 2 Oct 2020 20:03:47 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 194CF20E0231; Fri, 2 Oct 2020 20:03:46 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 20:03:31 +0200 Message-Id: <20201002180331.20416-7-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002180331.20416-1-anton@khirnov.net> References: <20201002180331.20416-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] lavfi/vf_codecview: 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" X-TUID: 6mT7kOuwL7GV Content-Length: 3599 --- libavfilter/Makefile | 2 +- libavfilter/vf_codecview.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index be2c3e3156..119a9c513b 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -185,7 +185,7 @@ OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o OBJS-$(CONFIG_CHROMANR_FILTER) += vf_chromanr.o OBJS-$(CONFIG_CHROMASHIFT_FILTER) += vf_chromashift.o OBJS-$(CONFIG_CIESCOPE_FILTER) += vf_ciescope.o -OBJS-$(CONFIG_CODECVIEW_FILTER) += vf_codecview.o +OBJS-$(CONFIG_CODECVIEW_FILTER) += vf_codecview.o qp_table.o OBJS-$(CONFIG_COLORBALANCE_FILTER) += vf_colorbalance.o OBJS-$(CONFIG_COLORCHANNELMIXER_FILTER) += vf_colorchannelmixer.o OBJS-$(CONFIG_COLORKEY_FILTER) += vf_colorkey.o diff --git a/libavfilter/vf_codecview.c b/libavfilter/vf_codecview.c index 331bfba777..bdcbe42162 100644 --- a/libavfilter/vf_codecview.c +++ b/libavfilter/vf_codecview.c @@ -33,6 +33,7 @@ #include "libavutil/motion_vector.h" #include "libavutil/opt.h" #include "avfilter.h" +#include "qp_table.h" #include "internal.h" #define MV_P_FOR (1<<0) @@ -219,8 +220,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) AVFilterLink *outlink = ctx->outputs[0]; if (s->qp) { - int qstride, qp_type; - int8_t *qp_table = av_frame_get_qp_table(frame, &qstride, &qp_type); + int qstride, ret; + int8_t *qp_table; + + ret = ff_qp_table_extract(frame, &qp_table, &qstride, NULL); + if (ret < 0) { + av_frame_free(&frame); + return ret; + } if (qp_table) { int x, y; @@ -233,13 +240,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { - const int qp = ff_norm_qscale(qp_table[(y >> 3) * qstride + (x >> 3)], qp_type) * 128/31; + const int qp = ff_norm_qscale(qp_table[(y >> 3) * qstride + (x >> 3)], FF_QSCALE_TYPE_MPEG2) * 128/31; pu[x] = pv[x] = qp; } pu += lzu; pv += lzv; } } + av_freep(&qp_table); } if (s->mv || s->mv_type) {