Skip to content

Commit

Permalink
lavc/vaapi_encode_h265: add low_delay_b option for HEVC
Browse files Browse the repository at this point in the history
Low delay B-frame is supported on ICL+ platform.

For low power encoding, low_delay_b should be enabled by default.

Low delay B:
<http://what-when-how.com/Tutorial/topic-397pct9eq3/High-Efficiency-Video-Coding-HEVC-288.html>

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:
intel/libva#220
intel/libva#364
intel/media-driver#721

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
  • Loading branch information
fulinjie committed Apr 13, 2020
1 parent c455a28 commit 8230e4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions doc/encoders.texi
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions libavcodec/vaapi_encode_h265.c
Expand Up @@ -62,6 +62,7 @@ typedef struct VAAPIEncodeH265Context {
int tier;
int level;
int sei;
int low_delay_b;

// Derived settings.
int fixed_qp_idr;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 },
};
Expand Down

0 comments on commit 8230e4c

Please sign in to comment.