PR #21425 opened by hnsteyding URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21425 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21425.patch
Opus 1.6 now supports 96kHz samplerate: https://www.opus-codec.org/release/stable/2025/12/15/libopus-1_6.html I've created some PRs in HandBrake project (https://github.com/HandBrake/HandBrake): https://github.com/HandBrake/HandBrake/pull/7508 https://github.com/HandBrake/HandBrake/pull/7561 >From 9c38a5432818cab9b78c273792436cc2b47abaf8 Mon Sep 17 00:00:00 2001 From: hnsteyding <[email protected]> Date: Fri, 9 Jan 2026 22:00:09 +0000 Subject: [PATCH 1/3] libavcodec: enable 96kHz support for libopus 1.6 --- libavcodec/libopusdec.c | 2 +- libavcodec/libopusenc.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c index c602499b7c..a16eb4ec76 100644 --- a/libavcodec/libopusdec.c +++ b/libavcodec/libopusdec.c @@ -62,7 +62,7 @@ static av_cold int libopus_decode_init(AVCodecContext *avc) channels = 2; } - avc->sample_rate = 48000; + avc->sample_rate = 96000; avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ? AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16; av_channel_layout_uninit(&avc->ch_layout); diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c index 131886c8ea..0fbfb38982 100644 --- a/libavcodec/libopusenc.c +++ b/libavcodec/libopusenc.c @@ -97,7 +97,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count, bytestream_put_buffer(&p, "OpusHead", 8); bytestream_put_byte(&p, 1); /* Version */ bytestream_put_byte(&p, channels); - bytestream_put_le16(&p, avctx->initial_padding * 48000 / avctx->sample_rate); /* Lookahead samples at 48kHz */ + bytestream_put_le16(&p, avctx->initial_padding * 96000 / avctx->sample_rate); /* Lookahead samples at 96kHz */ bytestream_put_le32(&p, avctx->sample_rate); /* Original sample rate */ bytestream_put_le16(&p, 0); /* Gain of 0dB is recommended. */ @@ -267,7 +267,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx) int coupled_stream_count, header_size, frame_size; int mapping_family; - frame_size = opus->opts.frame_duration * 48000 / 1000; + frame_size = opus->opts.frame_duration * 96000 / 1000; switch (frame_size) { case 120: case 240: @@ -289,7 +289,7 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx) case 5760: #endif opus->opts.packet_size = - avctx->frame_size = frame_size * avctx->sample_rate / 48000; + avctx->frame_size = frame_size * avctx->sample_rate / 96000; break; default: av_log(avctx, AV_LOG_ERROR, "Invalid frame duration: %g.\n" @@ -577,7 +577,7 @@ static const FFCodecDefault libopus_defaults[] = { }; static const int libopus_sample_rates[] = { - 48000, 24000, 16000, 12000, 8000, 0, + 96000, 48000, 24000, 16000, 12000, 8000, 0, }; const FFCodec ff_libopus_encoder = { -- 2.49.1 >From 0cd5b35459f770d7780cfd37335594dc605cfa22 Mon Sep 17 00:00:00 2001 From: hnsteyding <[email protected]> Date: Fri, 9 Jan 2026 22:01:14 +0000 Subject: [PATCH 2/3] libavcodec/opus: enable 96kHz support for libopus 1.6 --- libavcodec/opus/dec.c | 2 +- libavcodec/opus/enc.c | 4 ++-- libavcodec/opus/parser.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c index 29c490ae37..58df2c7d4a 100644 --- a/libavcodec/opus/dec.c +++ b/libavcodec/opus/dec.c @@ -684,7 +684,7 @@ static av_cold int opus_decode_init(AVCodecContext *avctx) int ret; avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; - avctx->sample_rate = 48000; + avctx->sample_rate = 96000; c->fdsp = avpriv_float_dsp_alloc(0); if (!c->fdsp) diff --git a/libavcodec/opus/enc.c b/libavcodec/opus/enc.c index 8d20b6c192..b171f99a98 100644 --- a/libavcodec/opus/enc.c +++ b/libavcodec/opus/enc.c @@ -649,7 +649,7 @@ static av_cold int opus_encode_init(AVCodecContext *avctx) if (!avctx->bit_rate) { int coupled = ff_opus_default_coupled_streams[s->channels - 1]; - avctx->bit_rate = coupled*(96000) + (s->channels - coupled*2)*(48000); + avctx->bit_rate = coupled*(96000) + (s->channels - coupled*2)*(96000); } else if (avctx->bit_rate < 6000 || avctx->bit_rate > 255000 * s->channels) { int64_t clipped_rate = av_clip(avctx->bit_rate, 6000, 255000 * s->channels); av_log(avctx, AV_LOG_ERROR, "Unsupported bitrate %"PRId64" kbps, clipping to %"PRId64" kbps\n", @@ -746,7 +746,7 @@ const FFCodec ff_opus_encoder = { FF_CODEC_ENCODE_CB(opus_encode_frame), .close = opus_encode_end, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, - CODEC_SAMPLERATES(48000), + CODEC_SAMPLERATES(96000), CODEC_CH_LAYOUTS(AV_CHANNEL_LAYOUT_MONO, AV_CHANNEL_LAYOUT_STEREO), CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP), }; diff --git a/libavcodec/opus/parser.c b/libavcodec/opus/parser.c index bab0e50412..c16de65494 100644 --- a/libavcodec/opus/parser.c +++ b/libavcodec/opus/parser.c @@ -175,7 +175,7 @@ static int opus_parse(AVCodecParserContext *ctx, AVCodecContext *avctx, ParseContext *pc = &s->pc; int next, header_len = 0; - avctx->sample_rate = 48000; + avctx->sample_rate = 96000; if (avctx->extradata && !s->extradata_parsed) { if (ff_opus_parse_extradata(avctx, &s->ctx) < 0) { -- 2.49.1 >From a016696be12c8fffa80cf46d12439399f97cfe64 Mon Sep 17 00:00:00 2001 From: hnsteyding <[email protected]> Date: Fri, 9 Jan 2026 22:03:06 +0000 Subject: [PATCH 3/3] libavformat: enable 96kHz support for libopus 1.6 --- libavformat/oggenc.c | 2 +- libavformat/oggparseopus.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index 9a548a8d29..9f44869180 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -492,7 +492,7 @@ static int ogg_init(AVFormatContext *s) if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) /* Opus requires a fixed 48kHz clock */ - avpriv_set_pts_info(st, 64, 1, 48000); + avpriv_set_pts_info(st, 64, 1, 96000); else avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index ae4ff22c53..abf45b0f2b 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -71,10 +71,10 @@ static int parse_opus_header(AVFormatContext *avf, AVStream *st, struct ogg_stre memcpy(st->codecpar->extradata, packet, os->psize); - st->codecpar->sample_rate = 48000; + st->codecpar->sample_rate = 96000; st->codecpar->seek_preroll = av_rescale(OPUS_SEEK_PREROLL_MS, st->codecpar->sample_rate, 1000); - avpriv_set_pts_info(st, 64, 1, 48000); + avpriv_set_pts_info(st, 64, 1, 96000); priv->need_comments = 1; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
