From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C59F24934A for ; Thu, 8 Feb 2024 07:41:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A343F68D1DA; Thu, 8 Feb 2024 09:39:55 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5701368D1CF for ; Thu, 8 Feb 2024 09:39:52 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707377993; x=1738913993; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=U6SSSG0ojEXjPPSc+iDBat6uRV8FTVBGyUSaspazsrM=; b=LbB2dsOU/uo0l0wev8jbIIo4FGZx6++nCg/u9IAZEpUBQ+mbAHEvsma8 eHT6wwfZuoV3OvaIBzSfOp114VX8Ly22fCyiwnUCcebwImDDrUjch8n5s OWP/mLmmmoptHp/cA4Sy9lh4mSSx1vX2TLwzHNoV9kRZOAoaMC8rgX1Q3 TzzA5n1+txukhPjspL+z6wv5BYhxBuGhWu29h31WvpSUvP9cvfUYpGzHq srihI4uGEGNaZ7wzjaHEM8JAXvy2H6tdlS7PnL7TKpJZxMgrnXiCMGB9j hcqSQP0Y9D+ryRYbqDA4UFxiXMZ+9ak8SfuQGc2c4c4GYlID4k5rT2j/f Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18586599" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18586599" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 23:39:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1876328" Received: from xhh-dg264.sh.intel.com ([10.238.2.76]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 23:39:49 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Feb 2024 15:39:36 +0800 Message-Id: <20240208073936.1246837-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/qsvenc: update the selection of bitrate control method 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 Cc: Haihao Xiang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Haihao Xiang The default method is changed to CQP Signed-off-by: Haihao Xiang --- Changelog | 1 + doc/encoders.texi | 7 +++-- libavcodec/qsvenc.c | 59 +++++++++++++++++++++++++++------------ libavcodec/qsvenc_av1.c | 2 +- libavcodec/qsvenc_h264.c | 2 +- libavcodec/qsvenc_hevc.c | 2 +- libavcodec/qsvenc_mpeg2.c | 2 +- libavcodec/qsvenc_vp9.c | 2 +- 8 files changed, 52 insertions(+), 25 deletions(-) diff --git a/Changelog b/Changelog index c5fb21d198..b9e4536233 100644 --- a/Changelog +++ b/Changelog @@ -24,6 +24,7 @@ version : - ffmpeg CLI options may now be used as -/opt , which is equivalent to -opt > - showinfo bitstream filter +- Change the default bitrate control method from VBR to CQP for QSV encoders. version 6.1: - libaribcaption decoder diff --git a/doc/encoders.texi b/doc/encoders.texi index c9fe6d6143..d1363c2174 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3332,8 +3332,8 @@ quality range is 1 to 51, with 1 being the best quality. @end itemize @item -Otherwise, a bitrate-based mode is used. For all of those, you should specify at -least the desired average bitrate with the @option{b} option. +Otherwise when the desired average bitrate is specified with the @option{b} +option, a bitrate-based mode is used. @itemize @minus @item @var{LA} - VBR with lookahead, when the @option{look_ahead} option is specified. @@ -3354,6 +3354,9 @@ than the average bitrate. @option{avbr_accuracy} and @option{avbr_convergence} are set to non-zero. This mode is available for H264 and HEVC on Windows. @end itemize + +@item +Otherwise the default ratecontrol method @var{CQP} is used. @end itemize Note that depending on your system, a different mode than the one you specified diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index c63b72e384..8c6414f8ca 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -597,6 +597,12 @@ static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q) else if (want_vcm) { rc_mode = MFX_RATECONTROL_VCM; rc_desc = "video conferencing mode (VCM)"; + + if (!avctx->bit_rate) { + av_log(avctx, AV_LOG_ERROR, "Using the %s ratecontrol method. Please " + "use the b option to set the desired bitrate.\n", rc_desc); + return AVERROR(EINVAL); + } } #endif else if (want_la) { @@ -606,32 +612,49 @@ static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q) if (avctx->global_quality > 0) { rc_mode = MFX_RATECONTROL_LA_ICQ; rc_desc = "intelligent constant quality with lookahead (LA_ICQ)"; + } else if (!avctx->bit_rate) { + av_log(avctx, AV_LOG_ERROR, "Using the %s ratecontrol method. Please " + "use the b option to set the desired bitrate.\n", rc_desc); + return AVERROR(EINVAL); } } else if (avctx->global_quality > 0 && !avctx->rc_max_rate) { rc_mode = MFX_RATECONTROL_ICQ; rc_desc = "intelligent constant quality (ICQ)"; } - else if (avctx->rc_max_rate == avctx->bit_rate) { - rc_mode = MFX_RATECONTROL_CBR; - rc_desc = "constant bitrate (CBR)"; - } + else if (avctx->bit_rate) { + if (avctx->rc_max_rate == avctx->bit_rate) { + rc_mode = MFX_RATECONTROL_CBR; + rc_desc = "constant bitrate (CBR)"; + } #if QSV_HAVE_AVBR - else if (!avctx->rc_max_rate && - (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) && - q->avbr_accuracy && - q->avbr_convergence) { - rc_mode = MFX_RATECONTROL_AVBR; - rc_desc = "average variable bitrate (AVBR)"; - } + else if (!avctx->rc_max_rate && + (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) && + q->avbr_accuracy && + q->avbr_convergence) { + rc_mode = MFX_RATECONTROL_AVBR; + rc_desc = "average variable bitrate (AVBR)"; + } #endif - else if (avctx->global_quality > 0) { - rc_mode = MFX_RATECONTROL_QVBR; - rc_desc = "constant quality with VBR algorithm (QVBR)"; - } - else { - rc_mode = MFX_RATECONTROL_VBR; - rc_desc = "variable bitrate (VBR)"; + else if (avctx->global_quality > 0) { + rc_mode = MFX_RATECONTROL_QVBR; + rc_desc = "constant quality with VBR algorithm (QVBR)"; + } else { + rc_mode = MFX_RATECONTROL_VBR; + rc_desc = "variable bitrate (VBR)"; + } + } else { + rc_mode = MFX_RATECONTROL_CQP; + rc_desc = "constant quantization parameter (CQP)"; + if (avctx->codec_id == AV_CODEC_ID_AV1) + avctx->global_quality = FF_QP2LAMBDA * 128; + else + avctx->global_quality = FF_QP2LAMBDA * 26; + av_log(avctx, AV_LOG_WARNING, "Using the constant quantization " + "parameter (CQP) by default. Please use the global_quality " + "option and other options for a quality-based mode or the b " + "option and other options for a bitrate-based mode if the " + "default is not the desired choice.\n"); } q->param.mfx.RateControlMethod = rc_mode; diff --git a/libavcodec/qsvenc_av1.c b/libavcodec/qsvenc_av1.c index c697845d7b..c298eeb61c 100644 --- a/libavcodec/qsvenc_av1.c +++ b/libavcodec/qsvenc_av1.c @@ -129,7 +129,7 @@ static const AVClass class = { }; static const FFCodecDefault qsv_enc_defaults[] = { - { "b", "1M" }, + { "b", "0" }, { "g", "-1" }, { "bf", "-1" }, { "refs", "0" }, diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c index 071a9a79e9..004ed8076a 100644 --- a/libavcodec/qsvenc_h264.c +++ b/libavcodec/qsvenc_h264.c @@ -178,7 +178,7 @@ static const AVClass class = { }; static const FFCodecDefault qsv_enc_defaults[] = { - { "b", "1M" }, + { "b", "0" }, { "refs", "0" }, { "g", "-1" }, { "bf", "-1" }, diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index c5b7ac7cc4..c94855e99a 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -374,7 +374,7 @@ static const AVClass class = { }; static const FFCodecDefault qsv_enc_defaults[] = { - { "b", "1M" }, + { "b", "0" }, { "refs", "0" }, { "g", "248" }, { "bf", "-1" }, diff --git a/libavcodec/qsvenc_mpeg2.c b/libavcodec/qsvenc_mpeg2.c index 22f1ff7c0d..c2fb6fd8ff 100644 --- a/libavcodec/qsvenc_mpeg2.c +++ b/libavcodec/qsvenc_mpeg2.c @@ -82,7 +82,7 @@ static const AVClass class = { }; static const FFCodecDefault qsv_enc_defaults[] = { - { "b", "1M" }, + { "b", "0" }, { "refs", "0" }, // same as the x264 default { "g", "250" }, diff --git a/libavcodec/qsvenc_vp9.c b/libavcodec/qsvenc_vp9.c index d0340ef94b..8d26ec529c 100644 --- a/libavcodec/qsvenc_vp9.c +++ b/libavcodec/qsvenc_vp9.c @@ -93,7 +93,7 @@ static const AVClass class = { }; static const FFCodecDefault qsv_enc_defaults[] = { - { "b", "1M" }, + { "b", "0" }, { "refs", "0" }, { "g", "250" }, { "trellis", "-1" }, -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".