From patchwork Mon Mar 23 14:24:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 18369 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 B2C4A44B9C7 for ; Mon, 23 Mar 2020 16:30:27 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9780268B6FC; Mon, 23 Mar 2020 16:30:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5535B68B801 for ; Mon, 23 Mar 2020 16:30:20 +0200 (EET) IronPort-SDR: YMDjKdBDFPD21R8PyUQL+bhzp4K1FNQ50Ug3VDkAnY98Rh+s7YF06ze2DtZLPnqnQgnsWlpQQf eU3qe6LExVIQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2020 07:30:18 -0700 IronPort-SDR: +kgDMm9l8azHsV5b/yInAotIYQGXZ7Sew5W9W5X511zv7ErXlbwVGNSuWr8OU0c1C9H+NkUiqA Y8TR82eQAHzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,296,1580803200"; d="scan'208";a="445829154" Received: from icl-dev.sh.intel.com ([10.239.158.73]) by fmsmga005.fm.intel.com with ESMTP; 23 Mar 2020 07:30:17 -0700 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Mar 2020 22:24:39 +0800 Message-Id: <1584973479-32167-1-git-send-email-linjie.fu@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/vaapi_encode_h265: add h265 tile encoding support 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" Default to enable uniform_spacing_flag. Guess level by the tile rows/cols. Supported for ICL+ platforms. Also add documentations. To encode with 4 rows 2 columns: ffmpeg ... -c:v hevc_vaapi -tile_rows 4 -tile_cols 2 ... Signed-off-by: Linjie Fu --- doc/encoders.texi | 8 ++++++++ libavcodec/vaapi_encode_h265.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index e23b6b3..2dc5cd4 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3091,6 +3091,14 @@ Include HDR metadata if the input frames have it messages). @end table +@item tile_rows +Selects how many rows of tiles to encode with. For example, 4 tile rows would +be requested by setting the tile_rows option to 4. + +@item tile_cols +Selects how many columns of tiles to encode with. For example, 5 tile columns +would be requested by setting the tile_cols option to 5. + @end table @item mjpeg_vaapi diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 97dc5a7..457e3d9 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -63,6 +63,9 @@ typedef struct VAAPIEncodeH265Context { int level; int sei; + int trows; + int tcols; + // Derived settings. int fixed_qp_idr; int fixed_qp_p; @@ -345,7 +348,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) level = ff_h265_guess_level(ptl, avctx->bit_rate, ctx->surface_width, ctx->surface_height, - ctx->nb_slices, 1, 1, + ctx->nb_slices, ctx->tile_rows, ctx->tile_cols, (ctx->b_per_p > 0) + 1); if (level) { av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name); @@ -558,6 +561,20 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) pps->pps_loop_filter_across_slices_enabled_flag = 1; + if (ctx->tile_rows && ctx->tile_cols) { + pps->tiles_enabled_flag = 1; + pps->uniform_spacing_flag = 1; + + pps->num_tile_rows_minus1 = ctx->tile_rows - 1; + pps->num_tile_columns_minus1 = ctx->tile_cols - 1; + + pps->loop_filter_across_tiles_enabled_flag = 1; + + for (i = 0; i <= pps->num_tile_rows_minus1; i++) + pps->row_height_minus1[i] = ctx->row_height[i] - 1; + for (i = 0; i <= pps->num_tile_columns_minus1; i++) + pps->column_width_minus1[i] = ctx->col_width[i] - 1; + } // Fill VAAPI parameter buffers. @@ -666,6 +683,13 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) }, }; + if (pps->tiles_enabled_flag) { + for (i = 0; i <= vpic->num_tile_rows_minus1; i++) + vpic->row_height_minus1[i] = pps->row_height_minus1[i]; + for (i = 0; i <= vpic->num_tile_columns_minus1; i++) + vpic->column_width_minus1[i] = pps->column_width_minus1[i]; + } + return 0; } @@ -1181,6 +1205,11 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx) if (priv->qp > 0) ctx->explicit_qp = priv->qp; + if (priv->trows && priv->tcols) { + ctx->tile_rows = priv->trows; + ctx->tile_cols = priv->tcols; + } + return ff_vaapi_encode_init(avctx); } @@ -1257,6 +1286,11 @@ static const AVOption vaapi_encode_h265_options[] = { { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL }, INT_MIN, INT_MAX, FLAGS, "sei" }, + { "tile_rows", "Number of rows for tile encoding", + OFFSET(trows), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, + { "tile_cols", "Number of cols for tile encoding", + OFFSET(tcols), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, + { NULL }, };