Commit 5cb7e42bf7 for ffmpeg
commit 5cb7e42bf726a0ce64ae4bfe93de117008797bb7
Author: James Almer <jamrial@gmail.com>
Date: Wed Nov 4 10:29:14 2026 -0300
libavcodec/opus/dec: don't override sample rate if it's set
While the decoded output will always be 48000Hz, input parameters may be inherited
from the source audio used during encoding, including sample rate, timestamps, and
priming/trailing samples to discard.
Signed-off-by: James Almer <jamrial@gmail.com>
diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c
index 712a0351b6..c284f7a03b 100644
--- a/libavcodec/opus/dec.c
+++ b/libavcodec/opus/dec.c
@@ -507,6 +507,7 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
c->streams[0].silk_samplerate = get_silk_samplerate(pkt->config);
}
+ frame->sample_rate = 48000;
frame->nb_samples = coded_samples + delayed_samples;
/* no input or buffered data => nothing to do */
@@ -685,7 +686,8 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
int ret;
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
- avctx->sample_rate = 48000;
+ if (!avctx->sample_rate)
+ avctx->sample_rate = 48000;
c->fdsp = avpriv_float_dsp_alloc(0);
if (!c->fdsp)
@@ -731,7 +733,7 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
av_opt_set_int(s->swr, "out_sample_fmt", avctx->sample_fmt, 0);
av_opt_set_chlayout(s->swr, "in_chlayout", &layout, 0);
av_opt_set_chlayout(s->swr, "out_chlayout", &layout, 0);
- av_opt_set_int(s->swr, "out_sample_rate", avctx->sample_rate, 0);
+ av_opt_set_int(s->swr, "out_sample_rate", 48000, 0);
av_opt_set_int(s->swr, "filter_size", 16, 0);
ret = ff_silk_init(avctx, &s->silk, s->output_channels);