From 9baf5d8b4b2a6119a8406bb52a05d4a1b67f9a3e Mon Sep 17 00:00:00 2001 From: Jun Zhao <jun.z...@intel.com> Date: Tue, 1 Aug 2017 23:07:34 -0400 Subject: [V5 4/4] lavc/vaapi_encode_h265: respect "slices" option in h265 vaapi encoder
Enable multi-slice support in AVC/H.265 vaapi encoder. Signed-off-by: Wang, Yi A <yi.a.w...@intel.com> Signed-off-by: Jun Zhao <jun.z...@intel.com> --- libavcodec/vaapi_encode_h265.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index cf6b9388d1..a845b58094 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -176,6 +176,8 @@ typedef struct VAAPIEncodeH265Context { unsigned int ctu_width; unsigned int ctu_height; + int last_ctu_index; + int fixed_qp_idr; int fixed_qp_p; int fixed_qp_b; @@ -962,6 +964,7 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params; VAAPIEncodeH265Context *priv = ctx->priv_data; int i; + int slices; if (pic->type == PICTURE_TYPE_IDR) { av_assert0(pic->display_order == pic->encode_order); @@ -1024,7 +1027,19 @@ static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, av_assert0(0 && "invalid picture type"); } - pic->nb_slices = 1; + slices = 1; + if (ctx->max_slices) { + if (avctx->slices <= ctx->max_slices) { + slices = avctx->slices; + } else { + av_log(avctx, AV_LOG_ERROR, "The max slices number per frame " + "cannot more than %d.\n", ctx->max_slices); + return AVERROR_INVALIDDATA; + } + } + pic->nb_slices = slices; + + priv->last_ctu_index = 0; return 0; } @@ -1047,9 +1062,10 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, pslice = slice->priv_data; mslice = &pslice->misc_slice_params; - // Currently we only support one slice per frame. - vslice->slice_segment_address = 0; - vslice->num_ctu_in_slice = priv->ctu_width * priv->ctu_height; + vslice->slice_segment_address = priv->last_ctu_index; + vslice->num_ctu_in_slice = + ((slice->index + 1) * priv->ctu_width * priv->ctu_height) / pic->nb_slices - priv->last_ctu_index; + priv->last_ctu_index += vslice->num_ctu_in_slice; switch (pic->type) { case PICTURE_TYPE_IDR: @@ -1103,9 +1119,11 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, else vslice->slice_qp_delta = priv->fixed_qp_idr - vpic->pic_init_qp; - vslice->slice_fields.bits.last_slice_of_pic_flag = 1; + if (priv->last_ctu_index == priv->ctu_width * priv->ctu_height) + vslice->slice_fields.bits.last_slice_of_pic_flag = 1; - mslice->first_slice_segment_in_pic_flag = 1; + mslice->first_slice_segment_in_pic_flag = + !!(vslice->slice_segment_address == 0); if (pic->type == PICTURE_TYPE_IDR) { // No reference pictures. @@ -1198,6 +1216,10 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) av_assert0(0 && "Invalid RC mode."); } + if (!ctx->max_slices && avctx->slices > 0) + av_log(avctx, AV_LOG_WARNING, "The encode slice option is not " + "supported with the driver.\n"); + return 0; } -- 2.11.0
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel