@@ -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;
+ 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;
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;
}