From patchwork Mon Apr 13 04:32:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 18903 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 5325F449975 for ; Mon, 13 Apr 2020 07:39:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2EC0668B8F8; Mon, 13 Apr 2020 07:39:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D8A9B68B8D0 for ; Mon, 13 Apr 2020 07:39:44 +0300 (EEST) IronPort-SDR: NfGvDKfPD1jYM1dtj6f1281jaGlMbZxalrXIRHPPl2PlP7wpZd6CGF9J4jULn4CaKAXbNnMTYM d+sxQeZqkVfA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 21:39:42 -0700 IronPort-SDR: E601EGnVcgxrnPOP7/6yGQjyqzDpwdFoFjD2GrK6qMRlXnMTXsi04ssn23rrHQVp8eUnNchs0r h8Rhl6AnSWKg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="241563143" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by orsmga007.jf.intel.com with ESMTP; 12 Apr 2020 21:39:41 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Apr 2020 12:32:32 +0800 Message-Id: <1586752352-3030-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] lavc/vaapi_encode_h265: add low_delay_b option for HEVC 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: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Low delay B-frame is supported on ICL+ platform. For low power encoding, low_delay_b should be enabled by default. Low delay B: There is an on-going work in libva and media-driver to add querys support for low delay b, would add it once it's ready: https://github.com/intel/libva/pull/220 https://github.com/intel/libva/pull/364 https://github.com/intel/media-driver/issues/721 Signed-off-by: Linjie Fu --- doc/encoders.texi | 8 ++++++++ libavcodec/vaapi_encode_h265.c | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index e23b6b3..b0812be 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3089,6 +3089,14 @@ Some combination of the following values: Include HDR metadata if the input frames have it (@emph{mastering_display_colour_volume} and @emph{content_light_level} messages). + +@item low_delay_b +Use low delay B-frames instead of P frames. Reordering of pictures is +not allowed. The first picture is encoded as an I picture and subsequent +pictures are encoded as B pictures. Moreover, since past B pictures are +used for prediction, a low coding delay but with higher coding efficiency +(because of bi-prediction) is achieved. + @end table @end table diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 97dc5a7..cd48545 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -62,6 +62,7 @@ typedef struct VAAPIEncodeH265Context { int tier; int level; int sei; + int low_delay_b; // Derived settings. int fixed_qp_idr; @@ -894,6 +895,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, sh->slice_type = hpic->slice_type; + if (sh->slice_type == HEVC_SLICE_P && priv->low_delay_b) + sh->slice_type = HEVC_SLICE_B; + sh->slice_pic_order_cnt_lsb = hpic->pic_order_cnt & (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1; @@ -1054,9 +1058,13 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, vslice->ref_pic_list0[0] = vpic->reference_frames[0]; } if (pic->nb_refs >= 2) { - // Forward reference for B-frame. av_assert0(pic->type == PICTURE_TYPE_B); - vslice->ref_pic_list1[0] = vpic->reference_frames[1]; + if (priv->low_delay_b) + // Reference for low delay B-frame + vslice->ref_pic_list1[0] = vpic->reference_frames[0]; + else + // Forward reference for B-frame. + vslice->ref_pic_list1[0] = vpic->reference_frames[1]; } return 0; @@ -1181,6 +1189,11 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx) if (priv->qp > 0) ctx->explicit_qp = priv->qp; + /* low_delay_b is required for low power encoding */ + priv->low_delay_b = ctx->low_power ? 1 : priv->low_delay_b; + if (priv->low_delay_b) + av_log(avctx, AV_LOG_VERBOSE, "Low delay B-frame enabled.\n"); + return ff_vaapi_encode_init(avctx); } @@ -1256,6 +1269,8 @@ static const AVOption vaapi_encode_h265_options[] = { 0, AV_OPT_TYPE_CONST, { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL }, INT_MIN, INT_MAX, FLAGS, "sei" }, + { "low_delay_b", "Use low delay B frames instead of P frames", + OFFSET(low_delay_b), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS }, { NULL }, };