From patchwork Thu Sep 1 02:12:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 37584 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp6556pzh; Wed, 31 Aug 2022 19:15:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR5v8T/sklEzQW3utcgC1eFlwfrOQClQjPjDEh/PJNQC2ovIJm0H8LwHh5BhjKR0XK62lMdo X-Received: by 2002:a05:6402:19:b0:447:901f:6b28 with SMTP id d25-20020a056402001900b00447901f6b28mr26287639edu.392.1661998502570; Wed, 31 Aug 2022 19:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661998502; cv=none; d=google.com; s=arc-20160816; b=EeRs0bf/9eOOrfCB7Cb9IYuDCsuKmydKLleff+eoW2eW4x/lJzBJnrhpv4FlNY3sGd p+n0Gwt7V2F++UasK5wCM/saB9TBnKYpuC7cKHw2BnHTSxwlcrQe8qhvt9yEp6HLSWkD CEgPZscgTE8Gl5OeVsXSDwgHvm5jyQ7pH9MuLTZwCu0cb+1nITrHrr9OR9QNHdV1Qxdv ehEFHpr8fTvzEFPZyHEew9KvnfDPwORsTJz2+yCd9FPzLbYBUYiNSxaLGCjfhIQG3ZuB ki4KsDw2AY0X3lsF8rEQerWwdSkmpN7Xot0T6DQyasML1EFj+FJvFnqazz5/TJr/OpUv XcXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=czjFMVH8oWupE4tmKU1jHgUlaYWZQyQssiGcsaO3Izo=; b=jz7rGjyyGIxNSEzpOJ1X4FSBGCpfKEsykXaYzRVP6xUYbj31WZRCGhxrpdWjE1ysPz 2MmaI3i8rUDOdTLtAs4cRpUITdWGtdzxIXSX9tJhK1NCRg7aNAT4XofuM96rO/3c2NtU FDANUKTLiM8863b1TxrUJxFa0uj9CxNp4gD4jC2xyO6PZBDDhmqrtgbCwGskFqKso2Nk sXk+wl11LgmEUMbTcLgDjXQEC1WyKC8bHZjMwxHbm4Fqz95p4gzftO3bNl0wVGVdQPCb bj91H/ylTFmKtbyJ72QZdZZ4FHFVFPYt4gYIDHoIxx1pliHGPde3HhIvX2XkBKfPyDgB bnRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=DWHBCc9J; 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 a25-20020aa7d919000000b00447e8ccf579si582575edr.568.2022.08.31.19.14.37; Wed, 31 Aug 2022 19:15:02 -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=DWHBCc9J; 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 539E968B9F1; Thu, 1 Sep 2022 05:14:35 +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 083BB68B9E0 for ; Thu, 1 Sep 2022 05:14:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661998473; x=1693534473; h=from:to:cc:subject:date:message-id; bh=cWLKqTYX5yrhL6F4O3RuXEQgLNAvULptyLx24rHE6cs=; b=DWHBCc9Jed/oYI6E2F1MBNYMoVjFax8hOYAqH22sSlBiJ3xAOTMQg6z3 1wMHPj9YK7Bhb7CnjJCQzVjlZhv6w7jBrLTxesqOERptyNVuvwdk7vMre 8/L1HuEV4OnlzYxv0juLRbJaags5NYehU5zC0ZACW55BpMufXHXx273Br 3dgIXEZUwduSdDDZLkEhDAWMlmqU5hYBaJ1+/nU2kUcdazPshYW2/DcTi VyvhAShlaScg2FkPWPzfiH7mYtprTo7CeaPNDwAmjtx4A4EPkxgSvAsKZ yvL92QnjLbBserCZUcnyJ8pHqxY283e03iOCjPC2YMxZrLLAkO+LgdPSu A==; X-IronPort-AV: E=McAfee;i="6500,9779,10456"; a="381892097" X-IronPort-AV: E=Sophos;i="5.93,279,1654585200"; d="scan'208";a="381892097" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2022 19:14:22 -0700 X-IronPort-AV: E=Sophos;i="5.93,279,1654585200"; d="scan'208";a="608382255" Received: from xhh-dg164.sh.intel.com ([10.238.5.169]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2022 19:14:21 -0700 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Sep 2022 10:12:57 +0800 Message-Id: <20220901021257.9334-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] lavc/qsvenc: use VBR if maxrate is not specified on Windows 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: yuJFxIhFvetc From: Haihao Xiang Currently AVBR is disabled and VBR is the default method if maxrate is not specified on Linux, but AVBR is the default one if maxrate is not specified on Windows. In order to make user experience better accross Linux and Windows, use VBR by default on Windows if maxrate is not specified. User need to set both avbr_accuracy and avbr_convergence to non-zero explicitly and not to specify maxrate if AVBR is expected. In addition, AVBR works for H264 and HEVC only in the SDK. $ ffmpeg.exe -v verbose -f lavfi -i yuvtestsrc -vf "format=nv12" -c:v vp9_qsv -f null - --- doc/encoders.texi | 45 ++++++++++++++++++++++++++-------------- libavcodec/qsvenc.c | 5 ++++- libavcodec/qsvenc.h | 6 ++++-- libavcodec/qsvenc_h264.c | 1 + libavcodec/qsvenc_hevc.c | 1 + 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index d36464d629..d2046e437d 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3244,9 +3244,9 @@ the average bitrate. than the average bitrate. @item -@var{AVBR} - average VBR mode, when @option{maxrate} is not specified. This mode -is further configured by the @option{avbr_accuracy} and -@option{avbr_convergence} options. +@var{AVBR} - average VBR mode, when @option{maxrate} is not specified, both +@option{avbr_accuracy} and @option{avbr_convergence} are set to non-zero. This +mode is available for H264 and HEVC on Windows. @end itemize @end itemize @@ -3300,19 +3300,6 @@ Specifies how many asynchronous operations an application performs before the application explicitly synchronizes the result. If zero, the value is not specified. -@item @var{avbr_accuracy} -Accuracy of the AVBR ratecontrol (unit of tenth of percent). - -@item @var{avbr_convergence} -Convergence of the AVBR ratecontrol (unit of 100 frames) - -The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the -average variable bitrate control (AVBR) algorithm. -The algorithm focuses on overall encoding quality while meeting the specified -bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy}, -after a @var{avbr_Convergence} period. This method does not follow HRD and the -instant bitrate is not capped or padded. - @item @var{preset} This option itemizes a range of choices from veryfast (best speed) to veryslow (best quality). @@ -3518,6 +3505,19 @@ Provides a hint to encoder about the scenario for the encoding session. @item remotegaming @end table +@item @var{avbr_accuracy} +Accuracy of the AVBR ratecontrol (unit of tenth of percent). + +@item @var{avbr_convergence} +Convergence of the AVBR ratecontrol (unit of 100 frames) + +The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the +average variable bitrate control (AVBR) algorithm. +The algorithm focuses on overall encoding quality while meeting the specified +bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy}, +after a @var{avbr_Convergence} period. This method does not follow HRD and the +instant bitrate is not capped or padded. + @end table @subsection HEVC Options @@ -3681,6 +3681,19 @@ Provides a hint to encoder about the scenario for the encoding session. @item remotegaming @end table +@item @var{avbr_accuracy} +Accuracy of the AVBR ratecontrol (unit of tenth of percent). + +@item @var{avbr_convergence} +Convergence of the AVBR ratecontrol (unit of 100 frames) + +The parameters @var{avbr_accuracy} and @var{avbr_convergence} are for the +average variable bitrate control (AVBR) algorithm. +The algorithm focuses on overall encoding quality while meeting the specified +bitrate, @var{target_bitrate}, within the accuracy range @var{avbr_accuracy}, +after a @var{avbr_Convergence} period. This method does not follow HRD and the +instant bitrate is not capped or padded. + @end table @subsection MPEG2 Options diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 7ac5390f10..31ff3b76ed 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -479,7 +479,10 @@ static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q) rc_desc = "constant bitrate (CBR)"; } #if QSV_HAVE_AVBR - else if (!avctx->rc_max_rate) { + 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)"; } diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index a983651dda..ff859f2a7e 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -52,8 +52,6 @@ #define QSV_COMMON_OPTS \ { "async_depth", "Maximum processing parallelism", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, { .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VE }, \ -{ "avbr_accuracy", "Accuracy of the AVBR ratecontrol (unit of tenth of percent)", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, UINT16_MAX, VE }, \ -{ "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100 frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, UINT16_MAX, VE }, \ { "preset", NULL, OFFSET(qsv.preset), AV_OPT_TYPE_INT, { .i64 = MFX_TARGETUSAGE_BALANCED }, MFX_TARGETUSAGE_BEST_QUALITY, MFX_TARGETUSAGE_BEST_SPEED, VE, "preset" }, \ { "veryfast", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_BEST_SPEED }, INT_MIN, INT_MAX, VE, "preset" }, \ { "faster", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_TARGETUSAGE_6 }, INT_MIN, INT_MAX, VE, "preset" }, \ @@ -124,6 +122,10 @@ { "gamestreaming", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCENARIO_GAME_STREAMING }, .flags = VE, "scenario" }, \ { "remotegaming", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_SCENARIO_REMOTE_GAMING }, .flags = VE, "scenario" }, +#define QSV_OPTION_AVBR \ +{ "avbr_accuracy", "Accuracy of the AVBR ratecontrol (unit of tenth of percent)", OFFSET(qsv.avbr_accuracy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE }, \ +{ "avbr_convergence", "Convergence of the AVBR ratecontrol (unit of 100 frames)", OFFSET(qsv.avbr_convergence), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UINT16_MAX, VE }, + extern const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[]; typedef int SetEncodeCtrlCB (AVCodecContext *avctx, diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c index a0dc31e24a..4b29ccac0f 100644 --- a/libavcodec/qsvenc_h264.c +++ b/libavcodec/qsvenc_h264.c @@ -115,6 +115,7 @@ static const AVOption options[] = { QSV_OPTION_LOW_DELAY_BRC QSV_OPTION_MAX_MIN_QP QSV_OPTION_SCENARIO + QSV_OPTION_AVBR { "cavlc", "Enable CAVLC", OFFSET(qsv.cavlc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, #if QSV_HAVE_VCM diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index e59747fda3..29086337fb 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -236,6 +236,7 @@ static const AVOption options[] = { QSV_OPTION_ADAPTIVE_I QSV_OPTION_ADAPTIVE_B QSV_OPTION_SCENARIO + QSV_OPTION_AVBR { "idr_interval", "Distance (in I-frames) between IDR frames", OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT_MAX, VE, "idr_interval" }, { "begin_only", "Output an IDR-frame only at the beginning of the stream", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, VE, "idr_interval" },