VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
- memset(&priv->current_access_unit, 0,
- sizeof(priv->current_access_unit));
-
memset(sps, 0, sizeof(*sps));
memset(pps, 0, sizeof(*pps));
sps->level_idc = avctx->level;
} else {
const H264LevelDescriptor *level;
+ int framerate;
+
+ if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ framerate = avctx->framerate.num / avctx->framerate.den;
+ else
+ framerate = 0;
level = ff_h264_guess_level(sps->profile_idc,
avctx->bit_rate,
+ framerate,
priv->mb_width * 16,
priv->mb_height * 16,
priv->dpb_frames);
(ctx->va_bit_rate >> hrd->bit_rate_scale + 6) - 1;
hrd->cpb_size_scale =
- av_clip_uintp2(av_log2(ctx->hrd_params.hrd.buffer_size) - 15 - 4, 4);
+ av_clip_uintp2(av_log2(ctx->hrd_params.buffer_size) - 15 - 4, 4);
hrd->cpb_size_value_minus1[0] =
- (ctx->hrd_params.hrd.buffer_size >> hrd->cpb_size_scale + 4) - 1;
+ (ctx->hrd_params.buffer_size >> hrd->cpb_size_scale + 4) - 1;
// CBR mode as defined for the HRD cannot be achieved without filler
// data, so this flag cannot be set even with VAAPI CBR modes.
// This calculation can easily overflow 32 bits.
bp->nal.initial_cpb_removal_delay[0] = 90000 *
- (uint64_t)ctx->hrd_params.hrd.initial_buffer_fullness /
- ctx->hrd_params.hrd.buffer_size;
+ (uint64_t)ctx->hrd_params.initial_buffer_fullness /
+ ctx->hrd_params.buffer_size;
bp->nal.initial_cpb_removal_delay_offset[0] = 0;
} else {
sps->vui.nal_hrd_parameters_present_flag = 0;
VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
int i;
- memset(&priv->current_access_unit, 0,
- sizeof(priv->current_access_unit));
-
if (pic->type == PICTURE_TYPE_IDR) {
av_assert0(pic->display_order == pic->encode_order);
priv->mb_height = FFALIGN(avctx->height, 16) / 16;
if (ctx->va_rc_mode == VA_RC_CQP) {
- priv->fixed_qp_p = priv->qp;
+ priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
if (avctx->i_quant_factor > 0.0)
- priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor +
- avctx->i_quant_offset) + 0.5);
+ priv->fixed_qp_idr =
+ av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
+ avctx->i_quant_offset) + 0.5, 1, 51);
else
priv->fixed_qp_idr = priv->fixed_qp_p;
if (avctx->b_quant_factor > 0.0)
- priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor +
- avctx->b_quant_offset) + 0.5);
+ priv->fixed_qp_b =
+ av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
+ avctx->b_quant_offset) + 0.5, 1, 51);
else
priv->fixed_qp_b = priv->fixed_qp_p;
- priv->sei &= ~SEI_TIMING;
-
av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
"%d / %d / %d for IDR- / P- / B-frames.\n",
priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
- } else if (ctx->va_rc_mode == VA_RC_CBR ||
- ctx->va_rc_mode == VA_RC_VBR) {
+ } else {
// These still need to be set for pic_init_qp/slice_qp_delta.
priv->fixed_qp_idr = 26;
priv->fixed_qp_p = 26;
priv->fixed_qp_b = 26;
+ }
- } else {
- av_assert0(0 && "Invalid RC mode.");
+ if (!ctx->rc_mode->hrd) {
+ // Timing SEI requires a mode respecting HRD parameters.
+ priv->sei &= ~SEI_TIMING;
}
if (priv->sei & SEI_IDENTIFIER) {
}
}
+ ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
+
return 0;
}
FLAG_B_PICTURE_REFERENCES |
FLAG_NON_IDR_KEY_PICTURES,
+ .default_quality = 20,
+
.configure = &vaapi_encode_h264_configure,
.picture_priv_data_size = sizeof(VAAPIEncodeH264Picture),
ctx->slice_block_height = ctx->slice_block_width = 16;
+ if (priv->qp > 0)
+ ctx->explicit_qp = priv->qp;
+
return ff_vaapi_encode_init(avctx);
}
#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
static const AVOption vaapi_encode_h264_options[] = {
VAAPI_ENCODE_COMMON_OPTIONS,
+ VAAPI_ENCODE_RC_OPTIONS,
{ "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
- OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS },
+ OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
{ "quality", "Set encode quality (trades off against speed, higher is faster)",
OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
{ "coder", "Entropy coder type",