diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index 9aa35e2968..b46315b071 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -2382,10 +2382,10 @@ ensure_bitrate (GstVaapiEncoderH264 * encoder) if (!encoder->use_dct8x8) bits_per_mb += (bits_per_mb * 10) / 100; + guint64 factor = encoder->mb_width * encoder->mb_height * bits_per_mb; base_encoder->bitrate = - encoder->mb_width * encoder->mb_height * bits_per_mb * - GST_VAAPI_ENCODER_FPS_N (encoder) / - GST_VAAPI_ENCODER_FPS_D (encoder) / 1000; + gst_util_uint64_scale (factor, GST_VAAPI_ENCODER_FPS_N (encoder), + GST_VAAPI_ENCODER_FPS_D (encoder)) / 1000; GST_INFO ("target bitrate computed to %u kbps", base_encoder->bitrate); } break; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index 5d015baa78..b7fcc205a0 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -1947,10 +1947,10 @@ ensure_bitrate (GstVaapiEncoderH265 * encoder) /* Fixme: Provide better estimation */ /* Using a 1/6 compression ratio */ /* 12 bits per pixel fro yuv420 */ + guint64 factor = encoder->luma_width * encoder->luma_height * 12 / 6; base_encoder->bitrate = - (encoder->luma_width * encoder->luma_height * 12 / 6) * - GST_VAAPI_ENCODER_FPS_N (encoder) / - GST_VAAPI_ENCODER_FPS_D (encoder) / 1000; + gst_util_uint64_scale (factor, GST_VAAPI_ENCODER_FPS_N (encoder), + GST_VAAPI_ENCODER_FPS_D (encoder)) / 1000; GST_INFO ("target bitrate computed to %u kbps", base_encoder->bitrate); } break; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c index 0620d9f9be..9333307864 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c @@ -186,10 +186,11 @@ ensure_bitrate (GstVaapiEncoderMpeg2 * encoder) switch (GST_VAAPI_ENCODER_RATE_CONTROL (encoder)) { case GST_VAAPI_RATECONTROL_CBR: if (!base_encoder->bitrate) - base_encoder->bitrate = GST_VAAPI_ENCODER_WIDTH (encoder) * - GST_VAAPI_ENCODER_HEIGHT (encoder) * - GST_VAAPI_ENCODER_FPS_N (encoder) / - GST_VAAPI_ENCODER_FPS_D (encoder) / 4 / 1000; + base_encoder->bitrate = + gst_util_uint64_scale (GST_VAAPI_ENCODER_WIDTH (encoder) * + GST_VAAPI_ENCODER_HEIGHT (encoder), + GST_VAAPI_ENCODER_FPS_N (encoder), + GST_VAAPI_ENCODER_FPS_D (encoder)) / 4 / 1000; break; default: base_encoder->bitrate = 0; diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c index 65b449ed84..c23bd257b9 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_vp8.c @@ -125,10 +125,11 @@ ensure_bitrate (GstVaapiEncoderVP8 * encoder) switch (GST_VAAPI_ENCODER_RATE_CONTROL (encoder)) { case GST_VAAPI_RATECONTROL_CBR: if (!base_encoder->bitrate) { - base_encoder->bitrate = GST_VAAPI_ENCODER_WIDTH (encoder) * - GST_VAAPI_ENCODER_HEIGHT (encoder) * - GST_VAAPI_ENCODER_FPS_N (encoder) / - GST_VAAPI_ENCODER_FPS_D (encoder) / 4 * 1000; + base_encoder->bitrate = + gst_util_uint64_scale (GST_VAAPI_ENCODER_WIDTH (encoder) * + GST_VAAPI_ENCODER_HEIGHT (encoder), + GST_VAAPI_ENCODER_FPS_N (encoder), + GST_VAAPI_ENCODER_FPS_D (encoder)) / 4 * 1000; } default: base_encoder->bitrate = 0;