From patchwork Wed Dec 30 05:16:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 24682 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 463C6448A2E for ; Wed, 30 Dec 2020 07:18:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 20D5368A6B6; Wed, 30 Dec 2020 07:18:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5F84B68A64D for ; Wed, 30 Dec 2020 07:18:51 +0200 (EET) IronPort-SDR: RFR+aglsrodi7C8HgBaDrj+ldXvGzZo2iyii5LDMOpn/2fGkGnpGnVyLlKTK/qkVbMl0UagzpH zJfPh6U/iiJQ== X-IronPort-AV: E=McAfee;i="6000,8403,9849"; a="240651454" X-IronPort-AV: E=Sophos;i="5.78,460,1599548400"; d="scan'208";a="240651454" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Dec 2020 21:18:49 -0800 IronPort-SDR: ciFqWE/fOYe1fXJVIfxD3I6KmzYqqp2HjEGi60Hu/OgkIypadgM5/lBpd9lhEjHFVF//k9156o OToWZ/7TYsZQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,460,1599548400"; d="scan'208";a="347644474" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.3]) by fmsmga008.fm.intel.com with ESMTP; 29 Dec 2020 21:18:47 -0800 From: wenbin.chen@intel.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Dec 2020 13:16:17 +0800 Message-Id: <20201230051617.298203-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH V6] libavcodec/qsvenc: add low latency P-pyramid support for qsv 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 Cc: Wenbinc-Bin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Wenbinc-Bin Add low latency P-pyramid support for qsv, and it relates to a new command line parameter "-p_strategy". To enable this flag, user also need to set "-bf" to 0. P-strategy has two modes "1-simple" and "2-pyramid". Signed-off-by Wenbin Chen --- The details of the two models refer to https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#PRefType patch V2~V4: modify the coding style problem. patch V5: Forget to change "if" statement's coding style and fix it in V5. patch V6: Change the patch description's position in patch. libavcodec/qsvenc.c | 32 ++++++++++++++++++++++++++++++++ libavcodec/qsvenc.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 2bd2a56227..07df6f2364 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -268,6 +268,15 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break; default: av_log(avctx, AV_LOG_VERBOSE, "auto"); break; } + + av_log(avctx, AV_LOG_VERBOSE, "; PRefType: "); + switch (co3->PRefType) { + case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE, "default"); break; + case MFX_P_REF_SIMPLE: av_log(avctx, AV_LOG_VERBOSE, "simple"); break; + case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "pyramid"); break; + default: av_log(avctx, AV_LOG_VERBOSE, "unknown"); break; + } + av_log(avctx, AV_LOG_VERBOSE, "\n"); #endif @@ -777,6 +786,29 @@ FF_ENABLE_DEPRECATION_WARNINGS #if QSV_HAVE_CO3 q->extco3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3; q->extco3.Header.BufferSz = sizeof(q->extco3); + + switch (q->p_strategy) { + case 0: + q->extco3.PRefType = MFX_P_REF_DEFAULT; + break; + case 1: + q->extco3.PRefType = MFX_P_REF_SIMPLE; + break; + case 2: + q->extco3.PRefType = MFX_P_REF_PYRAMID; + break; + default: + q->extco3.PRefType = MFX_P_REF_DEFAULT; + av_log(avctx, AV_LOG_WARNING, "invalid p_strategy, set to default\n"); + break; + } + if ((q->extco3.PRefType == MFX_P_REF_SIMPLE || + q->extco3.PRefType == MFX_P_REF_PYRAMID) && + avctx->max_b_frames != 0) { + av_log(avctx, AV_LOG_WARNING, "Please set max_b_frames(-bf) to 0 to enable P-pyramid\n"); + } + + #if QSV_HAVE_GPB if (avctx->codec_id == AV_CODEC_ID_HEVC) q->extco3.GPB = q->gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index 6d305f87dd..1b6149cccf 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -95,6 +95,7 @@ { "adaptive_i", "Adaptive I-frame placement", OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \ { "adaptive_b", "Adaptive B-frame placement", OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \ { "b_strategy", "Strategy to choose between I/P/B-frames", OFFSET(qsv.b_strategy), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE }, \ +{ "p_strategy", "enable P-pyramid 0-default 1-simple 2-pyramid", OFFSET(qsv.p_strategy), AV_OPT_TYPE_INT, { .i64 = 0}, 0, 2, VE }, \ { "forced_idr", "Forcing I frames as IDR frames", OFFSET(qsv.forced_idr), AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1, VE }, \ { "low_power", "enable low power mode(experimental: many limitations by mfx version, BRC modes, etc.)", OFFSET(qsv.low_power), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, VE},\ @@ -181,6 +182,7 @@ typedef struct QSVEncContext { int extbrc; int adaptive_i; int adaptive_b; + int p_strategy; int b_strategy; int cavlc;