From 356dfc3bd120cbd52b8a03389bcf85cd269217cf Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 17 Sep 2026 18:02:03 +0200 Subject: [PATCH] avcodec/ituh263enc: compute the temporal reference with av_rescale_rnd() The hand written multiply and divide can overflow int64_t for a large time_base.num; av_rescale_rnd() computes the same truncating division exactly. --- libavcodec/ituh263enc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c index 56259783b0..e9c5d08a78 100644 --- a/libavcodec/ituh263enc.c +++ b/libavcodec/ituh263enc.c @@ -245,8 +245,8 @@ static int h263_encode_picture_header(MPVMainEncContext *const m) coded_frame_rate_base= (1000+best_clock_code)*best_divisor; put_bits(&s->pb, 22, 0x20); /* PSC */ - temp_ref = s->picture_number * (int64_t)coded_frame_rate * s->c.avctx->time_base.num / //FIXME use timestamp - (coded_frame_rate_base * (int64_t)s->c.avctx->time_base.den); + temp_ref = av_rescale_rnd(s->picture_number, coded_frame_rate * (int64_t)s->c.avctx->time_base.num, //FIXME use timestamp + coded_frame_rate_base * (int64_t)s->c.avctx->time_base.den, AV_ROUND_ZERO); put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */ put_bits(&s->pb, 1, 1); /* marker */