From patchwork Thu Aug 18 06:59:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 37338 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp148053pzh; Thu, 18 Aug 2022 00:01:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4qeeYIzPFY/hMUX9liAfidKK+uk+ysoeaPZv2c5PpySuqFOsbFlJmpJryuEDHIUSV90wHy X-Received: by 2002:a17:907:c0e:b0:731:614:e507 with SMTP id ga14-20020a1709070c0e00b007310614e507mr1066557ejc.529.1660806094224; Thu, 18 Aug 2022 00:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660806094; cv=none; d=google.com; s=arc-20160816; b=zeX1PX6RR6bEFP+fl+m1FFmqgTB0OvzgmaaXbVZHKTM/Yl3DlXrFhR94qaVhW9vJya 0MEp553K2gVMQVqupOA8FDWXUZNpt80AhE57d4hPhW45GH/14VC82/556KFlGZt8KdgF Z1Q3XHTH8x1Xc+WN/hw5WZXmGW6IENSaNt0ZyyQ2vK52BCc+eZuL5cK+T3CFRsDCEzXj v+eFVcT9xA/6R7GwDHRBOZECd1jfnAHlBecVUuFp0fauFTnl4AMwtfCRiUCLolEgYAb3 5Fh+ZSg6I3ZVV/lhEK7/n7FMzR7ulvsnurrTEl6lJ7xzAhzIJhYU8e46s3avYE6mRqmS LMbA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=J0OF0ITnXbRj1C3yOfTAPzUQZr8DSKS0Na+dX2V9/s0=; b=oPkXOCRI2kRa5PVo2g4UsyNOdm80aoOXh/670r/M3pLcxKf1CDaJZUsgCEZPNsgBSh GsOTXlwEcshk2Jgd54UA9Qgq9Nj3V0v4GU03q1lL2lXRr5kAudWlVrj1EfpqA41sX+rK zpAwhpp4fiev+fb6RjxfZBwxkI9O2DZzkX3lia9y2ELJ1+mPRGB6mV7yJVtqZ/lMuSdB vtd2WI5PUKOdTxOVONme9RBMJ/59kLXwKsAjCLLjG2Rm9ZY6eOXEMSiNgPGnP6X97lra uPvhL5ap1x8PakO0ZeBvcRJEzoYHaXM+ysK5tNy3ehchDVqIOh0tk92EzA8NfX0vUlVU 3h+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Kd9ugXlj; 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 hr2-20020a1709073f8200b0073096c2b51csi639233ejc.543.2022.08.18.00.01.33; Thu, 18 Aug 2022 00:01:34 -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=Kd9ugXlj; 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 4098468B985; Thu, 18 Aug 2022 10:01:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DFD5B68B8ED for ; Thu, 18 Aug 2022 10:01:22 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660806088; x=1692342088; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=Pg4udbW+ZUvsC2fVCo+BQVq1B/5FBrft8C/FoAKFpzA=; b=Kd9ugXljOHMSXxC7yxIIKROYNFtDzilrFMW7cX1e2ZzJF7boAs5gg2qy sy9mAeLgp+qGmBVIH0WLmf++8snL3hw/p/Hkp5FghK44ZNtrc35D8kAsP ZWR2VrYAZFWXzLfk1FXTVETYuie9oOKgF2Kac+QKhdxjgfOjMhBWHvfUf N5GscuGOU/aAkYtXrIUiwtxkBH8p48hI0SaMfNF98X6Yg0UgQ2YP76Y68 AKu1rBXFCiqNOJDQih8y4jT3ximchBLEbYig709VmyFIxUG/7tkdkMB+y 5dlD9hmrbgsKobgyidtRhhEepsN595Jq1LlVF2CwEBkBO9AGHAKlX/6vf w==; X-IronPort-AV: E=McAfee;i="6500,9779,10442"; a="378975921" X-IronPort-AV: E=Sophos;i="5.93,245,1654585200"; d="scan'208";a="378975921" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2022 00:01:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,245,1654585200"; d="scan'208";a="604155632" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga007.jf.intel.com with ESMTP; 18 Aug 2022 00:01:10 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Aug 2022 14:59:07 +0800 Message-Id: <20220818065912.158693-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] 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: waX6tGvkZwmT 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 6d73f74196..69fa46f3ea 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 4831640868..c911b81e7d 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -828,6 +828,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) @@ -1673,6 +1674,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) { @@ -1682,6 +1701,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 d35a1318f2..c452c5b806 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -235,6 +235,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);