mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-10 03:19:40 +00:00
encoder: h264,h265,mpeg2,vp8: use gst_util_uint64_scale() for bitrate
Use gst_util_uint64_scale() to calculate bitrate instead of normal arithmetic to avoid overflows, underflows and loss of precision. https://bugzilla.gnome.org/show_bug.cgi?id=768458
This commit is contained in:
parent
4259d1aec7
commit
68b9ab7818
4 changed files with 16 additions and 14 deletions
|
@ -2382,10 +2382,10 @@ ensure_bitrate (GstVaapiEncoderH264 * encoder)
|
||||||
if (!encoder->use_dct8x8)
|
if (!encoder->use_dct8x8)
|
||||||
bits_per_mb += (bits_per_mb * 10) / 100;
|
bits_per_mb += (bits_per_mb * 10) / 100;
|
||||||
|
|
||||||
|
guint64 factor = encoder->mb_width * encoder->mb_height * bits_per_mb;
|
||||||
base_encoder->bitrate =
|
base_encoder->bitrate =
|
||||||
encoder->mb_width * encoder->mb_height * bits_per_mb *
|
gst_util_uint64_scale (factor, GST_VAAPI_ENCODER_FPS_N (encoder),
|
||||||
GST_VAAPI_ENCODER_FPS_N (encoder) /
|
GST_VAAPI_ENCODER_FPS_D (encoder)) / 1000;
|
||||||
GST_VAAPI_ENCODER_FPS_D (encoder) / 1000;
|
|
||||||
GST_INFO ("target bitrate computed to %u kbps", base_encoder->bitrate);
|
GST_INFO ("target bitrate computed to %u kbps", base_encoder->bitrate);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1947,10 +1947,10 @@ ensure_bitrate (GstVaapiEncoderH265 * encoder)
|
||||||
/* Fixme: Provide better estimation */
|
/* Fixme: Provide better estimation */
|
||||||
/* Using a 1/6 compression ratio */
|
/* Using a 1/6 compression ratio */
|
||||||
/* 12 bits per pixel fro yuv420 */
|
/* 12 bits per pixel fro yuv420 */
|
||||||
|
guint64 factor = encoder->luma_width * encoder->luma_height * 12 / 6;
|
||||||
base_encoder->bitrate =
|
base_encoder->bitrate =
|
||||||
(encoder->luma_width * encoder->luma_height * 12 / 6) *
|
gst_util_uint64_scale (factor, GST_VAAPI_ENCODER_FPS_N (encoder),
|
||||||
GST_VAAPI_ENCODER_FPS_N (encoder) /
|
GST_VAAPI_ENCODER_FPS_D (encoder)) / 1000;
|
||||||
GST_VAAPI_ENCODER_FPS_D (encoder) / 1000;
|
|
||||||
GST_INFO ("target bitrate computed to %u kbps", base_encoder->bitrate);
|
GST_INFO ("target bitrate computed to %u kbps", base_encoder->bitrate);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -186,10 +186,11 @@ ensure_bitrate (GstVaapiEncoderMpeg2 * encoder)
|
||||||
switch (GST_VAAPI_ENCODER_RATE_CONTROL (encoder)) {
|
switch (GST_VAAPI_ENCODER_RATE_CONTROL (encoder)) {
|
||||||
case GST_VAAPI_RATECONTROL_CBR:
|
case GST_VAAPI_RATECONTROL_CBR:
|
||||||
if (!base_encoder->bitrate)
|
if (!base_encoder->bitrate)
|
||||||
base_encoder->bitrate = GST_VAAPI_ENCODER_WIDTH (encoder) *
|
base_encoder->bitrate =
|
||||||
GST_VAAPI_ENCODER_HEIGHT (encoder) *
|
gst_util_uint64_scale (GST_VAAPI_ENCODER_WIDTH (encoder) *
|
||||||
GST_VAAPI_ENCODER_FPS_N (encoder) /
|
GST_VAAPI_ENCODER_HEIGHT (encoder),
|
||||||
GST_VAAPI_ENCODER_FPS_D (encoder) / 4 / 1000;
|
GST_VAAPI_ENCODER_FPS_N (encoder),
|
||||||
|
GST_VAAPI_ENCODER_FPS_D (encoder)) / 4 / 1000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
base_encoder->bitrate = 0;
|
base_encoder->bitrate = 0;
|
||||||
|
|
|
@ -125,10 +125,11 @@ ensure_bitrate (GstVaapiEncoderVP8 * encoder)
|
||||||
switch (GST_VAAPI_ENCODER_RATE_CONTROL (encoder)) {
|
switch (GST_VAAPI_ENCODER_RATE_CONTROL (encoder)) {
|
||||||
case GST_VAAPI_RATECONTROL_CBR:
|
case GST_VAAPI_RATECONTROL_CBR:
|
||||||
if (!base_encoder->bitrate) {
|
if (!base_encoder->bitrate) {
|
||||||
base_encoder->bitrate = GST_VAAPI_ENCODER_WIDTH (encoder) *
|
base_encoder->bitrate =
|
||||||
GST_VAAPI_ENCODER_HEIGHT (encoder) *
|
gst_util_uint64_scale (GST_VAAPI_ENCODER_WIDTH (encoder) *
|
||||||
GST_VAAPI_ENCODER_FPS_N (encoder) /
|
GST_VAAPI_ENCODER_HEIGHT (encoder),
|
||||||
GST_VAAPI_ENCODER_FPS_D (encoder) / 4 * 1000;
|
GST_VAAPI_ENCODER_FPS_N (encoder),
|
||||||
|
GST_VAAPI_ENCODER_FPS_D (encoder)) / 4 * 1000;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
base_encoder->bitrate = 0;
|
base_encoder->bitrate = 0;
|
||||||
|
|
Loading…
Reference in a new issue