[FFmpeg-devel] [PATCH V4 4/4] lavc/vaapi_encode_h265: respect "slices" option in h265 vaapi encoder
Steven Liu
lingjiujianke at gmail.com
Wed Aug 23 14:12:28 EEST 2017
2017-08-23 18:34 GMT+08:00 Jun Zhao <mypopydev at gmail.com>:
>
>From dae9051c0828f7c86417308d06f1deb0640534bc Mon Sep 17 00:00:00 2001
From: Jun Zhao <jun.zhao at intel.com>
Date: Tue, 1 Aug 2017 23:07:34 -0400
Subject: [PATCH V4 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.wang at intel.com>
Signed-off-by: Jun Zhao <jun.zhao at intel.com>
---
libavcodec/vaapi_encode_h265.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index cf6b9388d1..e27b554a98 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 {
+ slices = avctx->slices;
What about move this "slices = avctx->slices;" out of the conditional ?
+ av_log(avctx, AV_LOG_WARNING, "The max slices number per frame "
+ "cannot more than %d.\n", slices);
+ }
+ }
+ 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,13 @@ 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;
+ if (vslice->slice_segment_address == 0)
+ mslice->first_slice_segment_in_pic_flag = 1;
+ else
+ mslice->first_slice_segment_in_pic_flag = 0;
What about:
mslice->first_slice_segment_in_pic_flag = vslice->slice_segment_address ? 0 : 1;
?
if (pic->type == PICTURE_TYPE_IDR) {
// No reference pictures.
@@ -1198,6 +1218,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 at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
More information about the ffmpeg-devel
mailing list