From patchwork Tue Sep 6 09:22:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 37690 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp3135540pzh; Tue, 6 Sep 2022 02:25:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4iixIEd3N3e55TqS8R+1Bi6/KA1oT3PReKv3At1Bljpj51NlN8X92imRGn5AZS0DhUSl9a X-Received: by 2002:a17:906:9748:b0:76f:b6c3:6d3d with SMTP id o8-20020a170906974800b0076fb6c36d3dmr304956ejy.753.1662456321683; Tue, 06 Sep 2022 02:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662456321; cv=none; d=google.com; s=arc-20160816; b=sdMw84AGxI4oUHOif3oSc2qXq8f4aSboXFRbkJf9wlfHIqd3Fi66aG1mSHazAGnJuQ pABQtc1oO+4YGzCZ4uOdjZIt2d3s9steGPvije4zm3A3SP4KaqcEgbgdSWPjjYbEBTWL mmjMs0LGOqiE9kirfhlZjtHoqfUrMFP51zDccBOCGOOXrQPQ0YTOPkO5C8a/dSAYI3vv AuGMCNwK3ok8u5HPpZ9P0WP2KiGpzrcVuhpnEMDN8Ul6o89jZzAOGOd93Feb2ZyYMvx6 6OmZsZqAgqTlLjcFmSFHRo2b83ZbjIJAtT0hW2Ih8X3pSYYl4BitpJqoy5lAf86JoUq+ 8tNw== 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:dkim-signature:delivered-to; bh=3zohgI5bT12sffWm1/pbCblNSv88ZUGyKsi6uvitNEs=; b=rrfxyKSHmSjodyOkw2CN2+EM9unk390dkzlB5e6WFJxaSZhHjfpuMlTDro1eKU3oM5 pI5aDZ8JNvB3anLiHAeQ6+eqAtoNaXtBTbWH3cdICDEdIAl7i24AbVMjgKLIB45lKzbZ NNmLzXug5r16p/2ngVmIkN0pgOQoR2nwvo8xiflo/Tvy7k0OPYPedJtQ4VUl29KnRS6x pMnaMHgHZjJTmVDn3cgfy204xfh9dTmmJP+SdmxAcSJJdq/wfBx+DqjJJcNtAM7nbU/N xbnZLTB97DY086tLjsFJfHsPVoqIem8OYsTq6NCEtSbp6qPamNOR74gvxHakkQXjqAT0 JaKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="L7GhH/M8"; 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 oz44-20020a1709077dac00b0076fa83bd1c3si246550ejc.359.2022.09.06.02.25.21; Tue, 06 Sep 2022 02:25:21 -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; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="L7GhH/M8"; 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 DAC6968B9AE; Tue, 6 Sep 2022 12:25:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 867E468BAAA for ; Tue, 6 Sep 2022 12:25:00 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662456305; x=1693992305; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=ERy8JaOWsk6L0XykZjN6R9QGqArSerPQEl5OYL109G8=; b=L7GhH/M8nfhT0eWBRpn4lDUVnBSE391XxSItVWGAsmvRMrd8M7zAY4Ow 9pGZIEJMZ/UDEM2fl+5N8M9qaQo5bxeRrkuK9u7G/BuPHrMJlrVI8yLas +aqm5if+ahYYhuBk1QIU5d7lhYhXnTHTFNT+t0YsOewIuRV+x38D7LvtP 2M45eYdJDvUWLqhDpSrf0Ybcq5jIYpPYI+tqHh8bkvIgOtwR8zdx1bkKL bjcVGcgwUiOewgVtD/w3MBOBR/LRuF/kZc1hVbH103UEV2c/eJBHTL+yb COkz5a2vSvkvtgRBQCLchNRxDym2mZJ00VlYY051+TTyJxLoR22VMIY2U g==; X-IronPort-AV: E=McAfee;i="6500,9779,10461"; a="322720547" X-IronPort-AV: E=Sophos;i="5.93,293,1654585200"; d="scan'208";a="322720547" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 02:24:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,293,1654585200"; d="scan'208";a="565028239" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga003.jf.intel.com with ESMTP; 06 Sep 2022 02:24:56 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Sep 2022 17:22:53 +0800 Message-Id: <20220906092258.994742-2-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220906092258.994742-1-wenbin.chen@intel.com> References: <20220906092258.994742-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/7] libavcodec/qsvenc: Add max_frame_size reset support to qsv X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: 7EZfFxxZMynd Signed-off-by: Wenbin Chen --- doc/encoders.texi | 4 ++++ libavcodec/qsvenc.c | 20 ++++++++++++++++++++ libavcodec/qsvenc.h | 2 ++ 3 files changed, 26 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index d36464d629..aadb6ab9fd 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3344,6 +3344,10 @@ Following options can be used durning qsv encoding. @item @var{b_quant_offset} Supported in h264_qsv and hevc_qsv. Change these value to reset qsv codec's qp configuration. + +@item @var{max_frame_size} +Supported in h264_qsv and hevc_qsv. +Change this value to reset qsv codec's MaxFrameSize configuration. @end table @subsection H264 options diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 842cfb845e..915a1abd26 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -824,6 +824,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; if (q->max_frame_size >= 0) q->extco2.MaxFrameSize = q->max_frame_size; + q->old_max_frame_size = q->max_frame_size; if (q->int_ref_type >= 0) q->extco2.IntRefType = q->int_ref_type; if (q->int_ref_cycle_size >= 0) @@ -1675,6 +1676,24 @@ static int update_qp(AVCodecContext *avctx, QSVEncContext *q) return updated; } +static int update_max_frame_size(AVCodecContext *avctx, QSVEncContext *q) +{ + int updated = 0; + + if (avctx->codec_id != AV_CODEC_ID_H264 && avctx->codec_id != AV_CODEC_ID_HEVC) + return 0; + + UPDATE_PARAM(q->old_max_frame_size, q->max_frame_size); + if (!updated) + return 0; + + q->extco2.MaxFrameSize = FFMAX(0, q->max_frame_size); + av_log(avctx, AV_LOG_DEBUG, + "Reset MaxFrameSize: %d;\n", q->extco2.MaxFrameSize); + + return updated; +} + static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame) { @@ -1684,6 +1703,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, return 0; needReset = update_qp(avctx, q); + needReset |= update_max_frame_size(avctx, q); if (!needReset) return 0; diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index a983651dda..3984ae7dd8 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -249,6 +249,8 @@ typedef struct QSVEncContext { float old_i_quant_offset; float old_b_quant_factor; float old_b_quant_offset; + // This is used for max_frame_size reset + int old_max_frame_size; } QSVEncContext; int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);