From 5b1fe9c68afcdd956dea6c43db529eb546cc1eb3 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Wed, 3 Apr 2019 14:12:23 +0800 Subject: [PATCH] libs: encoder: h264,h265: Set max_qp if min_qp is non-zero. media-driver currently fails to set a correct value of max_qp when min_qp is different to zero, in CBR and VBR mode, generating full quality frames, thus unexpected huge output. This patch sets max_qp to an arbitrary value to avoid this output temporary. Fixes: #144 --- gst-libs/gst/vaapi/gstvaapiencoder_h264.c | 4 ++++ gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c | 4 ++++ gst-libs/gst/vaapi/gstvaapiencoder_h265.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index e6947204d8..b87f420e83 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -2519,6 +2519,10 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder) GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp; + /* @FIXME: should not set this value, should be ignored if set to zero * + * https://github.com/intel/media-driver/issues/587 */ + if (encoder->min_qp > 0) + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).max_qp = 51; #if VA_CHECK_VERSION(1,0,0) GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).rc_flags.bits.mb_rate_control = diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c index 1ed8255afc..7bb95200b9 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264_fei.c @@ -2449,6 +2449,10 @@ ensure_misc_params (GstVaapiEncoderH264Fei * encoder, rate_control->window_size = encoder->cpb_length; rate_control->initial_qp = encoder->init_qp; rate_control->min_qp = encoder->min_qp; + /* @FIXME: should not set this value, should be ignored if set to zero * + * https://github.com/intel/media-driver/issues/587 */ + if (rate_control->min_qp > 0) + rate_control->max_qp = 51; rate_control->basic_unit_size = 0; gst_vaapi_enc_picture_add_misc_param (picture, misc); gst_vaapi_codec_object_replace (&misc, NULL); diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index a2e61d80a2..4290ad3713 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -1858,6 +1858,10 @@ ensure_control_rate_params (GstVaapiEncoderH265 * encoder) GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).window_size = encoder->cpb_length; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).initial_qp = encoder->init_qp; GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).min_qp = encoder->min_qp; + /* @FIXME: should not set this value, should be ignored if set to zero * + * https://github.com/intel/media-driver/issues/587 */ + if (encoder->min_qp > 0) + GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).max_qp = 51; #if VA_CHECK_VERSION(1,0,0) GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).rc_flags.bits.mb_rate_control =