Commit 8f3cccbca4 for ffmpeg
commit 8f3cccbca4a5f1f81ab7b990ce1acc4cb7b91abc
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sat Nov 21 10:24:32 2026 -0500
avcodec/opus/parser: report the duration in units of the sample rate
The parser duration is documented in units of AVCodecContext.sample_rate,
but the Opus parser reported it at 48 kHz whatever the rate. A demuxer
declaring another rate then gave packets a wrong duration.
diff --git a/libavcodec/opus/parser.c b/libavcodec/opus/parser.c
index 975acf2dfe..cfd2d22c40 100644
--- a/libavcodec/opus/parser.c
+++ b/libavcodec/opus/parser.c
@@ -91,7 +91,8 @@ static int set_frame_duration(AVCodecParserContext *ctx, AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
}
- ctx->duration = s->pkt.frame_count * s->pkt.frame_duration;
+ ctx->duration = av_rescale(s->pkt.frame_count * s->pkt.frame_duration,
+ avctx->sample_rate, OPUS_TIMESTAMP_RATE);
return 0;
}
diff --git a/tests/ref/fate/matroska-opus-rate44100 b/tests/ref/fate/matroska-opus-rate44100
index 3f88d91c8a..d4329d9c88 100644
--- a/tests/ref/fate/matroska-opus-rate44100
+++ b/tests/ref/fate/matroska-opus-rate44100
@@ -1,3 +1,3 @@
-packet|pts=-287|duration=960
-packet|pts=673|duration=960
+packet|pts=-287|duration=882
+packet|pts=595|duration=882
packet|pts=1477|duration=375