[PATCH 1/4] vaapi_encode: Move block size calculation after entrypoint selection
The block size can be dependent on the profile and entrypoint selected. It defaults to 16x16, with codecs able to override this choice with their own function. --- libavcodec/vaapi_encode.c | 14 ++++++++++++++ libavcodec/vaapi_encode.h | 6 ++++++ libavcodec/vaapi_encode_h265.c | 32 ++++++++++++++++++++++++++------ libavcodec/vaapi_encode_mjpeg.c | 16 +++++++++++++--- libavcodec/vaapi_encode_mpeg2.c | 3 --- libavcodec/vaapi_encode_vp8.c | 3 --- libavcodec/vaapi_encode_vp9.c | 14 ++++++++++---- 7 files changed, 69 insertions(+), 19 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 8ff720e395..93bbed4539 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1840,6 +1840,8 @@ static av_cold int vaapi_encode_init_slice_structure(AVCodecContext *avctx) return 0; } + av_assert0(ctx->slice_block_height > 0 && ctx->slice_block_width > 0); + ctx->slice_block_rows = (avctx->height + ctx->slice_block_height - 1) / ctx->slice_block_height; ctx->slice_block_cols = (avctx->width + ctx->slice_block_width - 1) / @@ -2237,6 +2239,18 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) if (err < 0) goto fail; + if (ctx->codec->block_size) { + ctx->codec->block_size(avctx); + } else { + // Assume 16x16 blocks. + ctx->surface_width = FFALIGN(avctx->width, 16); + ctx->surface_height = FFALIGN(avctx->height, 16); + if (ctx->codec->flags & FLAG_SLICE_CONTROL) { + ctx->slice_block_width = 16; + ctx->slice_block_height = 16; + } + } + err = vaapi_encode_init_rate_control(avctx); if (err < 0) goto fail; diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index b9a3defd72..583be9c845 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -355,6 +355,12 @@ typedef struct VAAPIEncodeType { // factor depending on RC mode. int default_quality; + // Determine block sizes for surface alignment and slices. This may + // need to query the profile and entrypoint, which will be available + // when this function is called. If not set, assume that all blocks + // are 16x16 and that surfaces should be aligned to match this. + void (*block_size)(AVCodecContext *avctx); + // Perform any extra codec-specific configuration after the // codec context is initialised (set up the private data and // add any necessary global parameters). diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 538862a9d5..9a78dfb4f7 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -55,6 +55,10 @@ typedef struct VAAPIEncodeH265Picture { typedef struct VAAPIEncodeH265Context { VAAPIEncodeContext common; + // Encoder features. + uint32_t ctu_size; + uint32_t min_cb_size; + // User options. int qp; int aud; @@ -1062,6 +1066,27 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, return 0; } +static av_cold void vaapi_encode_h265_block_size(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + VAAPIEncodeH265Context *priv = avctx->priv_data; + + if (!priv->ctu_size) { + priv->ctu_size = 32; + priv->min_cb_size = 16; + } + av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, " + "min CB size %dx%d.\n", priv->ctu_size, priv->ctu_size, + priv->min_cb_size, priv->min_cb_size); + + ctx->surface_width = FFALIGN(avctx->width, priv->min_cb_size); + ctx->surface_height = FFALIGN(avctx->height, priv->min_cb_size); + + ctx->slice_block_width = ctx->slice_block_height = priv->ctu_size; + + return; +} + static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -1127,6 +1152,7 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = { .default_quality = 25, + .block_size = &vaapi_encode_h265_block_size, .configure = &vaapi_encode_h265_configure, .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture), @@ -1172,12 +1198,6 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx) VA_ENC_PACKED_HEADER_SLICE | // Slice headers. VA_ENC_PACKED_HEADER_MISC; // SEI - ctx->surface_width = FFALIGN(avctx->width, 16); - ctx->surface_height = FFALIGN(avctx->height, 16); - - // CTU size is currently hard-coded to 32. - ctx->slice_block_width = ctx->slice_block_height = 32; - if (priv->qp > 0) ctx->explicit_qp = priv->qp; diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c index bd029cc903..0d992d6f44 100644 --- a/libavcodec/vaapi_encode_mjpeg.c +++ b/libavcodec/vaapi_encode_mjpeg.c @@ -434,6 +434,18 @@ static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, return 0; } +static av_cold void vaapi_encode_mjpeg_block_size(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + const AVPixFmtDescriptor *desc; + + desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format); + av_assert0(desc); + + ctx->surface_width = FFALIGN(avctx->width, 8 << desc->log2_chroma_w); + ctx->surface_height = FFALIGN(avctx->height, 8 << desc->log2_chroma_h); +} + static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -483,6 +495,7 @@ static const VAAPIEncodeType vaapi_encode_type_mjpeg = { .flags = FLAG_CONSTANT_QUALITY_ONLY | FLAG_INTRA_ONLY, + .block_size = &vaapi_encode_mjpeg_block_size, .configure = &vaapi_encode_mjpeg_configure, .default_quality = 80, @@ -509,9 +522,6 @@ static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx) ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_RAW_DATA; - ctx->surface_width = FFALIGN(avctx->width, 8); - ctx->surface_height = FFALIGN(avctx->height, 8); - return ff_vaapi_encode_init(avctx); } diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c index bac9ea1fa6..442321b55c 100644 --- a/libavcodec/vaapi_encode_mpeg2.c +++ b/libavcodec/vaapi_encode_mpeg2.c @@ -623,9 +623,6 @@ static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx) ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE; - ctx->surface_width = FFALIGN(avctx->width, 16); - ctx->surface_height = FFALIGN(avctx->height, 16); - return ff_vaapi_encode_init(avctx); } diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c index 6e7bf9d106..93d8b57316 100644 --- a/libavcodec/vaapi_encode_vp8.c +++ b/libavcodec/vaapi_encode_vp8.c @@ -210,9 +210,6 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx) // adding them anyway. ctx->desired_packed_headers = 0; - ctx->surface_width = FFALIGN(avctx->width, 16); - ctx->surface_height = FFALIGN(avctx->height, 16); - return ff_vaapi_encode_init(avctx); } diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c index d7f415d704..19093bfa71 100644 --- a/libavcodec/vaapi_encode_vp9.c +++ b/libavcodec/vaapi_encode_vp9.c @@ -176,6 +176,15 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx, return 0; } +static av_cold void vaapi_encode_vp9_block_size(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + + // Surfaces must be aligned to 64x64 superblock boundaries. + ctx->surface_width = FFALIGN(avctx->width, 64); + ctx->surface_height = FFALIGN(avctx->height, 64); +} + static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -223,6 +232,7 @@ static const VAAPIEncodeType vaapi_encode_type_vp9 = { .picture_priv_data_size = sizeof(VAAPIEncodeVP9Picture), + .block_size = &vaapi_encode_vp9_block_size, .configure = &vaapi_encode_vp9_configure, .sequence_params_size = sizeof(VAEncSequenceParameterBufferVP9), @@ -243,10 +253,6 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx) // can write its own headers and there is no metadata to include. ctx->desired_packed_headers = 0; - // Surfaces must be aligned to superblock boundaries. - ctx->surface_width = FFALIGN(avctx->width, 64); - ctx->surface_height = FFALIGN(avctx->height, 64); - return ff_vaapi_encode_init(avctx); } -- 2.25.0
max_14bit_constraint_flag should be set if the bit depth is not greater than 14 (currently always true). one_picture_only_flag should not be set because we don't support the still picture profiles. --- libavcodec/vaapi_encode_h265.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 9a78dfb4f7..dcc22eb610 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -330,6 +330,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) ptl->general_non_packed_constraint_flag = 1; ptl->general_frame_only_constraint_flag = 1; + ptl->general_max_14bit_constraint_flag = bit_depth <= 14; ptl->general_max_12bit_constraint_flag = bit_depth <= 12; ptl->general_max_10bit_constraint_flag = bit_depth <= 10; ptl->general_max_8bit_constraint_flag = bit_depth == 8; @@ -339,6 +340,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) ptl->general_max_monochrome_constraint_flag = chroma_format == 0; ptl->general_intra_constraint_flag = ctx->gop_size == 1; + ptl->general_one_picture_only_constraint_flag = 0; ptl->general_lower_bit_rate_constraint_flag = 1; -- 2.25.0
--- 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
-----Original Message----- From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Thursday, March 5, 2020 08:25 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 3/4] vaapi_encode_h265: Query encoding block sizes and features
--- 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.
The query looks good to me since I'm suffering from the differences of default parameters allowed for VDENC and VMEPAK in media-driver while adding support for low power encoding [1] for VAAPI. However got several questions: 1. Why not include PPS parameters as well? There are some differences in cu_qp_delta_enabled_flag and diff_cu_qp_delta_depth supported for VAEntrypointEncSliceLP. 2. Would it be better to only involve the variable parameters for sps/pps... ? This is what PR 379 [2] (unfinished) intended to do. 3. The suggested value of SAO enable flag could also be 1 in corresponding code in media-driver, which would provide 3% BD-Rate improvement with no fps penalty based on previous experiment with FFmpeg VAAPI. 4. There is separate media_libva_caps for gen11 and gen12, maybe need further update or centralization for the code in driver. (not tested yet, will do later) [1] https://github.com/intel-media-ci/ffmpeg-cartwheel/blob/master/patchset/0008... [2] https://github.com/intel/libva/pull/379 - Linjie
On 05/03/2020 05:13, Fu, Linjie wrote:
-----Original Message----- From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Thursday, March 5, 2020 08:25 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 3/4] vaapi_encode_h265: Query encoding block sizes and features
--- 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.
The query looks good to me since I'm suffering from the differences of default parameters allowed for VDENC and VMEPAK in media-driver while adding support for low power encoding [1] for VAAPI.
However got several questions:
1. Why not include PPS parameters as well? There are some differences in cu_qp_delta_enabled_flag and diff_cu_qp_delta_depth supported for VAEntrypointEncSliceLP.
Support for cu_qp_delta_enabled_flag is implied by the presence of non-CQP RC modes (maybe I should add a comment saying that explicitly?). The possible range of diff_cu_qp_delta_depth is set by min_cu_qp_delta_block_size_minus3, since the variable you actually want to define is Log2MinCuQpDeltaSize. (So for example that would be 1 if the smallest block supporting a qp_delta is 16x16 (Log2MinCuQpDeltaSize = 4), and then depth could be up to 2 on 64x64 CTBs or 1 on 32x32 CTBs.)
2. Would it be better to only involve the variable parameters for sps/pps... ? This is what PR 379 [2] (unfinished) intended to do.
I'm not sure what you mean by this question - all of these are variable parameters in SPS/PPS.
3. The suggested value of SAO enable flag could also be 1 in corresponding code in media-driver, which would provide 3% BD-Rate improvement with no fps penalty based on previous experiment with FFmpeg VAAPI.
Huh, nice. That never worked in Gen 9, so I guess that's another difference which needs the query information to express.
4. There is separate media_libva_caps for gen11 and gen12, maybe need further update or centralization for the code in driver. (not tested yet, will do later)
Since the documentation has not been released this needs someone from Intel to define what the capabilities actually are. As I wrote in the PR against iHD, all I have are guesses based on what I can observe working (or not). - Mark
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Sunday, March 8, 2020 00:31 To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH 3/4] vaapi_encode_h265: Query encoding block sizes and features
On 05/03/2020 05:13, Fu, Linjie wrote:
-----Original Message----- From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Thursday, March 5, 2020 08:25 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 3/4] vaapi_encode_h265: Query encoding block sizes and features
--- 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.
The query looks good to me since I'm suffering from the differences of default parameters allowed for VDENC and VMEPAK in media-driver while adding support for low power encoding [1] for VAAPI.
However got several questions:
1. Why not include PPS parameters as well? There are some differences in cu_qp_delta_enabled_flag and diff_cu_qp_delta_depth supported for VAEntrypointEncSliceLP.
Support for cu_qp_delta_enabled_flag is implied by the presence of non- CQP RC modes (maybe I should add a comment saying that explicitly?).
The possible range of diff_cu_qp_delta_depth is set by min_cu_qp_delta_block_size_minus3, since the variable you actually want to define is Log2MinCuQpDeltaSize. (So for example that would be 1 if the smallest block supporting a qp_delta is 16x16 (Log2MinCuQpDeltaSize = 4), and then depth could be up to 2 on 64x64 CTBs or 1 on 32x32 CTBs.)
Yes you are right, this should be not related with LP, setting the depth would make sense. Log2MinCuQpDeltaSize = CtbLog2SizeY − diff_cu_qp_delta_depth;
2. Would it be better to only involve the variable parameters for sps/pps... ? This is what PR 379 [2] (unfinished) intended to do.
I'm not sure what you mean by this question - all of these are variable parameters in SPS/PPS.
3. The suggested value of SAO enable flag could also be 1 in corresponding code in media-driver, which would provide 3% BD-Rate improvement with no fps penalty based on previous experiment with FFmpeg VAAPI.
Huh, nice. That never worked in Gen 9, so I guess that's another difference which needs the query information to express.
4. There is separate media_libva_caps for gen11 and gen12, maybe need further update or centralization for the code in driver. (not tested yet, will do later)
Since the documentation has not been released this needs someone from Intel to define what the capabilities actually are. As I wrote in the PR against iHD, all I have are guesses based on what I can observe working (or not).
I'll sync with media-driver and try to get capabilities for each platform. Thanks for the PRs in libva and iHD. - Linjie
--- With <https://github.com/intel/media-driver/pull/866>, intra-only 4:2:2 encode works on Ice Lake with something like: -vf 'format=yuyv422,hwupload' -c:v hevc_vaapi -g 1 out.mp4 There is still something wrong with inter frames. libavcodec/vaapi_encode_h265.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 59d150f503..79e3c70602 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -1197,6 +1197,10 @@ static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = { #if VA_CHECK_VERSION(0, 37, 0) { FF_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 }, { FF_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 }, +#endif +#if VA_CHECK_VERSION(1, 2, 0) + { FF_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 }, + { FF_PROFILE_HEVC_REXT, 10, 3, 1, 0, VAProfileHEVCMain422_10 }, #endif { FF_PROFILE_UNKNOWN } }; -- 2.25.0
-----Original Message----- From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Thursday, March 5, 2020 08:25 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 4/4] vaapi_encode_h265: Enable 4:2:2 support
--- With <https://github.com/intel/media-driver/pull/866>, intra-only 4:2:2 encode works on Ice Lake with something like:
-vf 'format=yuyv422,hwupload' -c:v hevc_vaapi -g 1 out.mp4
There is still something wrong with inter frames.
The possible reason is media-driver for gen11 (ice lake) lacks the capability query support for VAProfileHEVCMain422_10. With [1] applied in driver, the encoding for yuyv422 works well for me, for both intra and inter frames. Ps. In case you may be interested, I prepared several patches [2] for 4:2:2/4:4: 8/10 bit encoding. They works for me with correct outputs. And the reason for not upstreaming is: 1. 444 pixel format not ready; 2. recon surface of Y210 or 444 (AYUV and Y410 in media-driver) depends on the surface hint [3] in libva and corresponding code in media-driver to resize the recon surface which is not upstreamed yet. [1] https://github.com/intel/media-driver/pull/855/files [2] https://github.com/fulinjie/ffmpeg/commit/dfb153fa68029f2a4060bcfd8bf500fd8e... [3] https://github.com/intel/libva/pull/344 - Linjie
On 05/03/2020 02:49, Fu, Linjie wrote:
2. recon surface of Y210 or 444 (AYUV and Y410 in media-driver) depends on the surface hint [3] in libva and corresponding code in media-driver to resize the recon surface which is not upstreamed yet.
What is the reasoning for forcing the user to pass new extra attributes with this rather than handling it transparently so that it works like all other encoders? In some places in Mesa surfaces are reallocated with different properties when they are used for a purpose they don't currently support, which avoids weird constraints being exported to the user (e.g. see <https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/state_trackers/va/surface.c#n1000>). Since reconstructed picture surfaces are pretty unlikely to be used for anything else (just being copied out for debugging maybe?), it seems like an answer like that would be simpler in this case too. (Though perhaps I'm missing something weird about the Intel hardware which makes this case uglier.) - Mark
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Sunday, March 8, 2020 00:15 To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH 4/4] vaapi_encode_h265: Enable 4:2:2 support
On 05/03/2020 02:49, Fu, Linjie wrote:
2. recon surface of Y210 or 444 (AYUV and Y410 in media-driver) depends on the surface hint [3] in libva and corresponding code in media-driver to resize the recon surface which is not upstreamed yet.
What is the reasoning for forcing the user to pass new extra attributes with this rather than handling it transparently so that it works like all other encoders?
In some places in Mesa surfaces are reallocated with different properties when they are used for a purpose they don't currently support, which avoids weird constraints being exported to the user (e.g. see <https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/state_trackers/v a/surface.c#n1000>). Since reconstructed picture surfaces are pretty unlikely to be used for anything else (just being copied out for debugging maybe?), it seems like an answer like that would be simpler in this case too. (Though perhaps I'm missing something weird about the Intel hardware which makes this case uglier.)
Implemented the surface reallocation inside media driver in [1], merged the query support in [2], verified that it works for both AYUV(or XYUV)/Y410, yuyv422. And for Y210, it seems to be better to implement render target support in vaapi_encoder in this patch as well: { "YUV422_10", VA_RT_FORMAT_YUV422_10, 10, 3, 1, 0 }, Hence patch LGTM with or without above modifications, thx. - Linjie [1] < https://github.com/intel/media-driver/pull/915> [2] < https://github.com/intel/media-driver/pull/855>
On Fri, May 15, 2020 at 3:21 PM Fu, Linjie <linjie.fu@intel.com> wrote:
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Sunday, March 8, 2020 00:15 To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH 4/4] vaapi_encode_h265: Enable 4:2:2 support
On 05/03/2020 02:49, Fu, Linjie wrote:
2. recon surface of Y210 or 444 (AYUV and Y410 in media-driver) depends on the surface hint [3] in libva and corresponding code in media-driver to resize the recon surface which is not upstreamed yet.
What is the reasoning for forcing the user to pass new extra attributes with this rather than handling it transparently so that it works like all other encoders?
In some places in Mesa surfaces are reallocated with different properties when they are used for a purpose they don't currently support, which avoids weird constraints being exported to the user (e.g. see <https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/state_trackers/v a/surface.c#n1000>). Since reconstructed picture surfaces are pretty unlikely to be used for anything else (just being copied out for debugging maybe?), it seems like an answer like that would be simpler in this case too. (Though perhaps I'm missing something weird about the Intel hardware which makes this case uglier.)
Implemented the surface reallocation inside media driver in [1], merged the query support in [2], verified that it works for both AYUV(or XYUV)/Y410, yuyv422.
And for Y210, it seems to be better to implement render target support in vaapi_encoder in this patch as well: { "YUV422_10", VA_RT_FORMAT_YUV422_10, 10, 3, 1, 0 },
Hence patch LGTM with or without above modifications, thx.
[1] < https://github.com/intel/media-driver/pull/915> [2] < https://github.com/intel/media-driver/pull/855>
Since it's well supported for now, prefer to apply this soon together with the patch for 422 10-bit encoding : https://patchwork.ffmpeg.org/project/ffmpeg/patch/1595254554-12809-1-git-sen...
On Mon, Jul 20, 2020 at 10:32 PM Linjie Fu <linjie.justin.fu@gmail.com> wrote:
On Fri, May 15, 2020 at 3:21 PM Fu, Linjie <linjie.fu@intel.com> wrote:
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Mark Thompson Sent: Sunday, March 8, 2020 00:15 To: ffmpeg-devel@ffmpeg.org Subject: Re: [FFmpeg-devel] [PATCH 4/4] vaapi_encode_h265: Enable 4:2:2 support
On 05/03/2020 02:49, Fu, Linjie wrote:
2. recon surface of Y210 or 444 (AYUV and Y410 in media-driver) depends on the surface hint [3] in libva and corresponding code in media-driver to resize the recon surface which is not upstreamed yet.
What is the reasoning for forcing the user to pass new extra attributes with this rather than handling it transparently so that it works like all other encoders?
In some places in Mesa surfaces are reallocated with different properties when they are used for a purpose they don't currently support, which avoids weird constraints being exported to the user (e.g. see <https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/state_trackers/v a/surface.c#n1000>). Since reconstructed picture surfaces are pretty unlikely to be used for anything else (just being copied out for debugging maybe?), it seems like an answer like that would be simpler in this case too. (Though perhaps I'm missing something weird about the Intel hardware which makes this case uglier.)
Implemented the surface reallocation inside media driver in [1], merged the query support in [2], verified that it works for both AYUV(or XYUV)/Y410, yuyv422.
And for Y210, it seems to be better to implement render target support in vaapi_encoder in this patch as well: { "YUV422_10", VA_RT_FORMAT_YUV422_10, 10, 3, 1, 0 },
Hence patch LGTM with or without above modifications, thx.
[1] < https://github.com/intel/media-driver/pull/915> [2] < https://github.com/intel/media-driver/pull/855>
Since it's well supported for now, prefer to apply this soon together with the patch for 422 10-bit encoding :
https://patchwork.ffmpeg.org/project/ffmpeg/patch/1595254554-12809-1-git-sen...
Applied, thx. - Linjie
participants (3)
-
Fu, Linjie -
Linjie Fu -
Mark Thompson