libs: encoder: h264: support ICQ/QVBR bitrate control mode

ICQ is Intelligent Constant Quality. It will use the initial QP
vaule of icq-quality-factor to adjust QP at MB level intelligently
to improve subjective quality.

QVBR is Quality defined VBR. It will use qvbr-quality-factor to
adjust QP for each MB to get enough quality picture without waste
of bits.
This commit is contained in:
Wangfei 2019-07-18 13:32:46 +08:00
parent f5c9d86f9c
commit 9e0c133a24
5 changed files with 71 additions and 1 deletions

View file

@ -54,7 +54,9 @@
(GST_VAAPI_RATECONTROL_MASK (CQP) | \ (GST_VAAPI_RATECONTROL_MASK (CQP) | \
GST_VAAPI_RATECONTROL_MASK (CBR) | \ GST_VAAPI_RATECONTROL_MASK (CBR) | \
GST_VAAPI_RATECONTROL_MASK (VBR) | \ GST_VAAPI_RATECONTROL_MASK (VBR) | \
GST_VAAPI_RATECONTROL_MASK (VBR_CONSTRAINED)) GST_VAAPI_RATECONTROL_MASK (VBR_CONSTRAINED) | \
GST_VAAPI_RATECONTROL_MASK (ICQ) | \
GST_VAAPI_RATECONTROL_MASK (QVBR))
/* Supported set of tuning options, within this implementation */ /* Supported set of tuning options, within this implementation */
#define SUPPORTED_TUNE_OPTIONS \ #define SUPPORTED_TUNE_OPTIONS \
@ -753,6 +755,7 @@ struct _GstVaapiEncoderH264
guint32 num_bframes; guint32 num_bframes;
guint32 mb_width; guint32 mb_width;
guint32 mb_height; guint32 mb_height;
guint32 quality_factor;
gboolean use_cabac; gboolean use_cabac;
gboolean use_dct8x8; gboolean use_dct8x8;
guint temporal_levels; /* Number of temporal levels */ guint temporal_levels; /* Number of temporal levels */
@ -2514,6 +2517,14 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder)
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP) if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_CQP)
return TRUE; return TRUE;
#if VA_CHECK_VERSION(1,1,0)
if (GST_VAAPI_ENCODER_RATE_CONTROL (encoder) == GST_VAAPI_RATECONTROL_ICQ) {
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).ICQ_quality_factor =
encoder->quality_factor;
return TRUE;
}
#endif
/* RateControl params */ /* RateControl params */
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second = GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).bits_per_second =
encoder->bitrate_bits; encoder->bitrate_bits;
@ -2530,6 +2541,11 @@ ensure_control_rate_params (GstVaapiEncoderH264 * encoder)
(guint) encoder->mbbrc; (guint) encoder->mbbrc;
#endif #endif
#if VA_CHECK_VERSION(1,3,0)
GST_VAAPI_ENCODER_VA_RATE_CONTROL (encoder).quality_factor =
encoder->quality_factor;
#endif
/* HRD params */ /* HRD params */
fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder)); fill_hrd_params (encoder, &GST_VAAPI_ENCODER_VA_HRD (encoder));
@ -2681,6 +2697,7 @@ ensure_bitrate (GstVaapiEncoderH264 * encoder)
case GST_VAAPI_RATECONTROL_CBR: case GST_VAAPI_RATECONTROL_CBR:
case GST_VAAPI_RATECONTROL_VBR: case GST_VAAPI_RATECONTROL_VBR:
case GST_VAAPI_RATECONTROL_VBR_CONSTRAINED: case GST_VAAPI_RATECONTROL_VBR_CONSTRAINED:
case GST_VAAPI_RATECONTROL_QVBR:
if (!base_encoder->bitrate) { if (!base_encoder->bitrate) {
/* According to the literature and testing, CABAC entropy coding /* According to the literature and testing, CABAC entropy coding
mode could provide for +10% to +18% improvement in general, mode could provide for +10% to +18% improvement in general,
@ -3552,6 +3569,9 @@ gst_vaapi_encoder_h264_set_property (GstVaapiEncoder * base_encoder,
case GST_VAAPI_ENCODER_H264_PROP_MAX_QP: case GST_VAAPI_ENCODER_H264_PROP_MAX_QP:
encoder->max_qp = g_value_get_uint (value); encoder->max_qp = g_value_get_uint (value);
break; break;
case GST_VAAPI_ENCODER_H264_PROP_QUALITY_FACTOR:
encoder->quality_factor = g_value_get_uint (value);
break;
default: default:
return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER; return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_PARAMETER;
@ -3838,6 +3858,19 @@ gst_vaapi_encoder_h264_get_default_properties (void)
gst_vaapi_encoder_h264_compliance_mode_type (), gst_vaapi_encoder_h264_compliance_mode_type (),
GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_STRICT, G_PARAM_READWRITE)); GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_STRICT, G_PARAM_READWRITE));
/**
* GstVaapiEncoderH264:quality_factor:
*
* quality factor used under ICQ/QVBR bitrate control mode.
*/
GST_VAAPI_ENCODER_PROPERTIES_APPEND (props,
GST_VAAPI_ENCODER_H264_PROP_QUALITY_FACTOR,
g_param_spec_uint ("quality-factor",
"Quality factor for ICQ/QVBR",
"quality factor for ICQ/QVBR bitrate control mode"
"(low value means higher-quality, higher value means lower-quality)",
1, 51, 26, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
return props; return props;
} }

View file

@ -57,6 +57,7 @@ typedef struct _GstVaapiEncoderH264 GstVaapiEncoderH264;
* @GST_VAAPI_ENCODER_H264_PROP_TEMPORAL_LEVELS: Number of temporal levels * @GST_VAAPI_ENCODER_H264_PROP_TEMPORAL_LEVELS: Number of temporal levels
* @GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE: Reference picture selection modes * @GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE: Reference picture selection modes
* @GST_VAAPI_ENCODER_H264_PROP_MAX_QP: Maximal quantizer value (uint). * @GST_VAAPI_ENCODER_H264_PROP_MAX_QP: Maximal quantizer value (uint).
* @GST_VAAPI_ENCODER_H264_PROP_QUALITY_FACTOR: Factor for ICQ/QVBR bitrate control mode.
* *
* The set of H.264 encoder specific configurable properties. * The set of H.264 encoder specific configurable properties.
*/ */
@ -79,6 +80,7 @@ typedef enum {
GST_VAAPI_ENCODER_H264_PROP_TEMPORAL_LEVELS = -16, GST_VAAPI_ENCODER_H264_PROP_TEMPORAL_LEVELS = -16,
GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE = -17, GST_VAAPI_ENCODER_H264_PROP_PREDICTION_TYPE = -17,
GST_VAAPI_ENCODER_H264_PROP_MAX_QP = -18, GST_VAAPI_ENCODER_H264_PROP_MAX_QP = -18,
GST_VAAPI_ENCODER_H264_PROP_QUALITY_FACTOR = -19,
} GstVaapiEncoderH264Prop; } GstVaapiEncoderH264Prop;
GstVaapiEncoder * GstVaapiEncoder *

View file

@ -148,6 +148,10 @@ typedef enum {
* @GST_VAAPI_RATECONTROL_VBR_CONSTRAINED: Variable bitrate with peak * @GST_VAAPI_RATECONTROL_VBR_CONSTRAINED: Variable bitrate with peak
* rate higher than average bitrate * rate higher than average bitrate
* @GST_VAAPI_RATECONTROL_MB: Macroblock based rate control * @GST_VAAPI_RATECONTROL_MB: Macroblock based rate control
* @GST_VAAPI_RATECONTROL_ICQ: Intelligent Constant QP, use
* quality_factor to improve subjective quality base on motion
* @GST_VAAPI_RATECONTROL_QVBR: Quality defined VBR, use
* quality_factor to get good enough quality and save bits
* *
* The set of allowed rate control values for #GstVaapiRateControl. * The set of allowed rate control values for #GstVaapiRateControl.
* Note: this is only valid for encoders. * Note: this is only valid for encoders.
@ -160,6 +164,8 @@ typedef enum {
GST_VAAPI_RATECONTROL_VBR, GST_VAAPI_RATECONTROL_VBR,
GST_VAAPI_RATECONTROL_VBR_CONSTRAINED, GST_VAAPI_RATECONTROL_VBR_CONSTRAINED,
GST_VAAPI_RATECONTROL_MB, GST_VAAPI_RATECONTROL_MB,
GST_VAAPI_RATECONTROL_ICQ,
GST_VAAPI_RATECONTROL_QVBR,
} GstVaapiRateControl; } GstVaapiRateControl;
/* Define a mask for GstVaapiRateControl */ /* Define a mask for GstVaapiRateControl */

View file

@ -341,6 +341,14 @@ string_of_VARateControl (guint rate_control)
#if VA_CHECK_VERSION(0,39,1) #if VA_CHECK_VERSION(0,39,1)
case VA_RC_MB: case VA_RC_MB:
return "MB"; return "MB";
#endif
#if VA_CHECK_VERSION(1,1,0)
case VA_RC_ICQ:
return "VA_RC_ICQ";
#endif
#if VA_CHECK_VERSION(1,3,0)
case VA_RC_QVBR:
return "VA_RC_QVBR";
#endif #endif
default: default:
break; break;
@ -710,6 +718,14 @@ from_GstVaapiRateControl (guint value)
#if VA_CHECK_VERSION(0,39,1) #if VA_CHECK_VERSION(0,39,1)
case GST_VAAPI_RATECONTROL_MB: case GST_VAAPI_RATECONTROL_MB:
return VA_RC_MB; return VA_RC_MB;
#endif
#if VA_CHECK_VERSION(1,1,0)
case GST_VAAPI_RATECONTROL_ICQ:
return VA_RC_ICQ;
#endif
#if VA_CHECK_VERSION(1,3,0)
case GST_VAAPI_RATECONTROL_QVBR:
return VA_RC_QVBR;
#endif #endif
} }
GST_ERROR ("unsupported GstVaapiRateControl value %u", value); GST_ERROR ("unsupported GstVaapiRateControl value %u", value);
@ -736,6 +752,15 @@ to_GstVaapiRateControl (guint value)
case VA_RC_MB: case VA_RC_MB:
return GST_VAAPI_RATECONTROL_MB; return GST_VAAPI_RATECONTROL_MB;
#endif #endif
#if VA_CHECK_VERSION(1,1,0)
case VA_RC_ICQ:
return GST_VAAPI_RATECONTROL_ICQ;
#endif
#if VA_CHECK_VERSION(1,3,0)
case VA_RC_QVBR:
return GST_VAAPI_RATECONTROL_QVBR;
#endif
} }
GST_ERROR ("unsupported VA-API Rate Control value %u", value); GST_ERROR ("unsupported VA-API Rate Control value %u", value);
return GST_VAAPI_RATECONTROL_NONE; return GST_VAAPI_RATECONTROL_NONE;

View file

@ -150,6 +150,10 @@ gst_vaapi_rate_control_get_type (void)
"Variable bitrate - Constrained", "vbr_constrained"}, "Variable bitrate - Constrained", "vbr_constrained"},
{GST_VAAPI_RATECONTROL_MB, {GST_VAAPI_RATECONTROL_MB,
"Macroblock based rate control", "mb"}, "Macroblock based rate control", "mb"},
{GST_VAAPI_RATECONTROL_ICQ,
"Constant QP - Intelligent", "icq"},
{GST_VAAPI_RATECONTROL_QVBR,
"Variable bitrate - Quality defined", "qvbr"},
{0, NULL, NULL}, {0, NULL, NULL},
}; };