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