From 5c67bdaf63edd6451dafd1c4bf946a825b099fa1 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 29 May 2020 16:40:20 +0800 Subject: [PATCH] libs: encoder: h265: Use correct index for SubWidthC and SubHeightC. We need to use the chroma_format_idc as the index for getting the SubWidthC and SubHeightC values as the spec 6.1(table 6-1) defines. The wrong SubWidthC or SubHeightC make us calculate a wrong right or bottom offset for crop size and generate garbage in output. Part-of: --- gst-libs/gst/vaapi/gstvaapiencoder_h265.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index bee501f20b..dd785f4cb8 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -2712,17 +2712,22 @@ gst_vaapi_encoder_h265_reconfigure (GstVaapiEncoder * base_encoder) /* Frame Cropping */ if ((GST_VAAPI_ENCODER_WIDTH (encoder) & 15) || (GST_VAAPI_ENCODER_HEIGHT (encoder) & 15)) { + /* 6.1, Table 6-1 */ static const guint SubWidthC[] = { 1, 2, 2, 1 }; static const guint SubHeightC[] = { 1, 2, 1, 1 }; + guint index = gst_vaapi_utils_h265_get_chroma_format_idc + (gst_vaapi_video_format_get_chroma_type (GST_VIDEO_INFO_FORMAT + (GST_VAAPI_ENCODER_VIDEO_INFO (encoder)))); + encoder->conformance_window_flag = 1; encoder->conf_win_left_offset = 0; encoder->conf_win_right_offset = (encoder->luma_width - - GST_VAAPI_ENCODER_WIDTH (encoder)) / SubWidthC[1]; + GST_VAAPI_ENCODER_WIDTH (encoder)) / SubWidthC[index]; encoder->conf_win_top_offset = 0; encoder->conf_win_bottom_offset = (encoder->luma_height - - GST_VAAPI_ENCODER_HEIGHT (encoder)) / SubHeightC[1]; + GST_VAAPI_ENCODER_HEIGHT (encoder)) / SubHeightC[index]; } }