[FFmpeg-devel] [PATCH 3/4] vaapi_encode_h265: Query encoding block sizes and features
Mark Thompson
sw at jkqxz.net
Thu Mar 5 02:25:27 EET 2020
---
Requires <https://github.com/intel/libva/pull/385>. That isn't upstream, so this will need to wait for that and then get at least a fix to the version numbering before applying.
libavcodec/vaapi_encode_h265.c | 91 +++++++++++++++++++++++++++-------
1 file changed, 74 insertions(+), 17 deletions(-)
diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c
index dcc22eb610..59d150f503 100644
--- a/libavcodec/vaapi_encode_h265.c
+++ b/libavcodec/vaapi_encode_h265.c
@@ -56,6 +56,7 @@ typedef struct VAAPIEncodeH265Context {
VAAPIEncodeContext common;
// Encoder features.
+ uint32_t va_features;
uint32_t ctu_size;
uint32_t min_cb_size;
@@ -440,23 +441,54 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
vps->vps_max_latency_increase_plus1[i];
}
- // These have to come from the capabilities of the encoder. We have no
- // way to query them, so just hardcode parameters which work on the Intel
- // driver.
- // CTB size from 8x8 to 32x32.
- sps->log2_min_luma_coding_block_size_minus3 = 0;
- sps->log2_diff_max_min_luma_coding_block_size = 2;
- // Transform size from 4x4 to 32x32.
- sps->log2_min_luma_transform_block_size_minus2 = 0;
- sps->log2_diff_max_min_luma_transform_block_size = 3;
- // Full transform hierarchy allowed (2-5).
- sps->max_transform_hierarchy_depth_inter = 3;
- sps->max_transform_hierarchy_depth_intra = 3;
- // AMP works.
- sps->amp_enabled_flag = 1;
- // SAO and temporal MVP do not work.
- sps->sample_adaptive_offset_enabled_flag = 0;
- sps->sps_temporal_mvp_enabled_flag = 0;
+#if VA_CHECK_VERSION(1, 7, 0)
+ if (priv->va_features) {
+ VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
+
+ sps->log2_min_luma_coding_block_size_minus3 =
+ ff_ctz(priv->min_cb_size) - 3;
+ sps->log2_diff_max_min_luma_coding_block_size =
+ ff_ctz(priv->ctu_size) - ff_ctz(priv->min_cb_size);
+
+ sps->log2_min_luma_transform_block_size_minus2 =
+ features.bits.log2_min_luma_transform_block_size_minus2;
+ sps->log2_diff_max_min_luma_transform_block_size =
+ features.bits.log2_max_luma_transform_block_size_minus2 -
+ features.bits.log2_min_luma_transform_block_size_minus2;
+
+ sps->max_transform_hierarchy_depth_inter =
+ features.bits.max_transform_hierarchy_depth_inter;
+ sps->max_transform_hierarchy_depth_intra =
+ features.bits.max_transform_hierarchy_depth_intra;
+
+ sps->amp_enabled_flag =
+ features.bits.amp_supported;
+ sps->sample_adaptive_offset_enabled_flag =
+ features.bits.sao_supported;
+ sps->sps_temporal_mvp_enabled_flag =
+ features.bits.temporal_mvp_supported;
+ } else
+#endif
+ {
+ // These values come from the capabilities of the first encoder
+ // implementation in the i965 driver on Intel Skylake. They may
+ // fail badly with other platforms or drivers.
+ // CTB size from 8x8 to 32x32.
+ sps->log2_min_luma_coding_block_size_minus3 = 0;
+ sps->log2_diff_max_min_luma_coding_block_size = 2;
+ // Transform size from 4x4 to 32x32.
+ sps->log2_min_luma_transform_block_size_minus2 = 0;
+ sps->log2_diff_max_min_luma_transform_block_size = 3;
+ // Full transform hierarchy allowed (2-5).
+ sps->max_transform_hierarchy_depth_inter = 3;
+ sps->max_transform_hierarchy_depth_intra = 3;
+ // AMP works.
+ sps->amp_enabled_flag = 1;
+ // SAO and temporal MVP do not work.
+ sps->sample_adaptive_offset_enabled_flag = 0;
+ sps->sps_temporal_mvp_enabled_flag = 0;
+ }
+
sps->pcm_enabled_flag = 0;
@@ -1073,6 +1105,31 @@ static av_cold void vaapi_encode_h265_block_size(AVCodecContext *avctx)
VAAPIEncodeContext *ctx = avctx->priv_data;
VAAPIEncodeH265Context *priv = avctx->priv_data;
+#if VA_CHECK_VERSION(1, 7, 0)
+ {
+ VAConfigAttrib attr = { VAConfigAttribEncHEVCFeatures };
+ VAConfigAttribValEncHEVCFeatures features;
+ VAStatus vas;
+
+ vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
+ ctx->va_entrypoint, &attr, 1);
+ if (vas != VA_STATUS_SUCCESS) {
+ av_log(avctx, AV_LOG_WARNING, "Failed to query encoder "
+ "features, using guessed defaults.\n");
+ } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
+ av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
+ "encoder features, using guessed defaults.\n");
+ } else {
+ features.value = priv->va_features = attr.value;
+
+ priv->ctu_size =
+ 1 << features.bits.log2_max_coding_tree_block_size_minus3 + 3;
+ priv->min_cb_size =
+ 1 << features.bits.log2_min_luma_coding_block_size_minus3 + 3;
+ }
+ }
+#endif
+
if (!priv->ctu_size) {
priv->ctu_size = 32;
priv->min_cb_size = 16;
--
2.25.0
More information about the ffmpeg-devel
mailing list