PR #26088 opened by Baptiste Coudurier (bcoudurier)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26088
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26088.patch

ELD configurations with low-delay SBR currently retain the AAC core sample rate 
and frame length in the shared configuration parser. For dual-rate streams this 
makes container metadata and sample-based trimming use the wrong output rate.

Read `ldSbrPresentFlag` and `ldSbrSamplingRate`, set the SBR extension sample 
rate, and scale the derived frame length for dual-rate output. Reject truncated 
input before reading the added ELD fields. AAC-LD parsing and the native 
decoder's existing rejection of unsupported low-delay SBR remain unchanged.

For the Apple ELDv2 `aacg.mp4` fixture, stream discovery reports 44,100 Hz 
instead of 22,050 Hz, with initial padding 714 instead of 357 and terminal 
discard 86 instead of 43. The packet clock remains 22,050 Hz. No MOV timing or 
sample-entry changes are included.

Validation on the submitted commit:

- Built `ffmpeg` and `ffprobe`; all 43 enabled AAC FATE targets passed.
- Standalone parser checks passed under AddressSanitizer and 
UndefinedBehaviorSanitizer: 192 combinations covering indexed/explicit rates, 
480/512 core frame sizes, absent/single-rate/dual-rate SBR, both sync-extension 
settings, and all eight bit alignments, plus the original ELDv2 ASC. All tested 
truncations of the newly parsed ELD fields were rejected.
- The same patch also passed three MOV priming regression targets in the audio 
integration tree before rebasing onto upstream.



>From 654817bb820358d653541b4e296f17a149d0ded3 Mon Sep 17 00:00:00 2001
From: Baptiste Coudurier <[email protected]>
Date: Sun, 15 Nov 2026 14:18:59 -0800
Subject: [PATCH] avcodec/mpeg4audio: read the output rate of low-delay SBR

Parse the ELD low-delay SBR presence and sampling-rate flags. Derive the 
extension sample rate and output frame length so MOV trimming uses decoded 
samples for dual-rate ELD streams.

Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavcodec/mpeg4audio.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c
index 0430568b631..f1490fdfcde 100644
--- a/libavcodec/mpeg4audio.c
+++ b/libavcodec/mpeg4audio.c
@@ -143,10 +143,27 @@ int ff_mpeg4audio_get_config_gb(MPEG4AudioConfig *c, 
GetBitContext *gb,
         c->frame_length = c->frame_length_short ? 960 : 1024;
         break;
     case AOT_ER_AAC_LD:
-    case AOT_ER_AAC_ELD:
         c->frame_length_short = get_bits1(gb);
         c->frame_length = c->frame_length_short ? 480 : 512;
         break;
+    case AOT_ER_AAC_ELD:
+        if (get_bits_left(gb) < 5)
+            return AVERROR_INVALIDDATA;
+        c->frame_length_short = get_bits1(gb);
+        c->frame_length = c->frame_length_short ? 480 : 512;
+        skip_bits(gb, 3); /* resilience flags */
+        c->sbr = get_bits1(gb);
+        if (c->sbr) {
+            int dual_rate;
+
+            if (get_bits_left(gb) < 1)
+                return AVERROR_INVALIDDATA;
+            dual_rate = get_bits1(gb);
+            c->ext_object_type = AOT_SBR;
+            c->ext_sample_rate = c->sample_rate << dual_rate;
+            c->frame_length <<= dual_rate;
+        }
+        break;
     case AOT_USAC: {
         int core_sbr_frame_len_idx, sbr_ratio;
         int ratio_mult, ratio_dec, frame_length;
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to