PR #26205 opened by alexdonzel
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26205
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26205.patch
# Summary of changes
The AAC decoder rejects AAC-ELD at sample rates outside 22.05-48 kHz
("Unsupported sample rate index N for LD/ELD"), because the 480 and 512 sample
band tables are only defined for that range. HomeKit cameras and video
doorbells send 16 kHz mono AAC-ELD with 480 sample frames, so FFmpeg (and
go2rtc, Home Assistant and others that use it) can't decode their audio.
The first commit maps other rates to the nearest defined table, which is what
the FDK AAC decoder does: the 48 kHz tables above 48 kHz and the 24 kHz tables
below 22.05 kHz. Compared with the FDK decoder, output is 79.5-80.5 dB SNR from
8 to 96 kHz with both frame lengths, the same as at 32-48 kHz. Output at
22.05-48 kHz is unchanged. This also fixes ticket #8182 (16 kHz mono ELD with
512 sample frames).
The second commit adds a FATE test with a 16 kHz, 480 sample frame ELD stream
(LATM in MPEG-TS, encoded with libfdk-aac) and an FDK-decoded reference. It
fails without the first commit.
Separately, I noticed FFmpeg and FDK disagree at 22.05/24 kHz ELD with some
encoder settings even without this change. It's unrelated, so I'll report it on
its own.
```fate-samples
aac/aac_eld_16k_480.ts
aac/aac_eld_16k_480.s16
```
>From e5c9b19debb16e551d72e3806aadb44f7781b955 Mon Sep 17 00:00:00 2001
From: alexdonzel <[email protected]>
Date: Thu, 19 Nov 2026 15:30:02 +0000
Subject: [PATCH 1/2] avcodec/aactab: support AAC-ELD at sample rates outside
22.05-48 kHz
ISO/IEC 14496-3 only defines the 480 and 512 sample scalefactor band tables
for 22.05 to 48 kHz, so the decoder rejected AAC-ELD at other rates with
"Unsupported sample rate index N for LD/ELD". Such streams exist: HomeKit
cameras and video doorbells send 16 kHz mono AAC-ELD with 480 sample frames.
Use the 48 kHz tables above 48 kHz and the 24 kHz tables below 22.05 kHz,
which is what the FDK AAC decoder does (sfbOffsetTables and
tns_max_bands_tbl_480/512 in libAACdec/src/aac_rom.cpp). AAC-LD is still
limited to 22.05-48 kHz when parsing the config, so the check in
decode_ics_info() can no longer trigger and is removed. Both the float and
fixed-point decoders use these tables.
Tested by encoding pink noise with libfdk-aac (ELD, LD-SBR off, LATM) at 8,
11.025, 12, 16, 64, 88.2 and 96 kHz with 480 and 512 sample frames and
comparing with the FDK decoder's output: 79.5 to 80.5 dB SNR, the same as at
32 to 48 kHz. Output at 22.05 to 48 kHz is unchanged.
Fixes ticket #8182.
Signed-off-by: alexdonzel <[email protected]>
---
libavcodec/aac/aacdec.c | 6 ------
libavcodec/aactab.c | 28 ++++++++++++++++------------
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c
index 4ac16844bed..834f51d5cf0 100644
--- a/libavcodec/aac/aacdec.c
+++ b/libavcodec/aac/aacdec.c
@@ -1507,12 +1507,6 @@ static int decode_ics_info(AACDecContext *ac,
IndividualChannelStream *ics,
ics->num_swb = ff_aac_num_swb_512[sampling_index];
ics->tns_max_bands = ff_tns_max_bands_512[sampling_index];
}
- if (!ics->num_swb || !ics->swb_offset) {
- av_log(ac->avctx, AV_LOG_ERROR,
- "Unsupported sample rate index %d for LD/ELD\n",
- sampling_index);
- goto fail;
- }
} else {
if (m4ac->frame_length_short) {
ics->num_swb = ff_aac_num_swb_960[sampling_index];
diff --git a/libavcodec/aactab.c b/libavcodec/aactab.c
index 128bacfdf19..891fd759809 100644
--- a/libavcodec/aactab.c
+++ b/libavcodec/aactab.c
@@ -159,11 +159,11 @@ const uint8_t ff_aac_num_swb_768[] = {
};
const uint8_t ff_aac_num_swb_512[] = {
- 0, 0, 0, 36, 36, 37, 31, 31, 0, 0, 0, 0, 0
+ 36, 36, 36, 36, 36, 37, 31, 31, 31, 31, 31, 31, 31
};
const uint8_t ff_aac_num_swb_480[] = {
- 0, 0, 0, 35, 35, 37, 30, 30, 0, 0, 0, 0, 0
+ 35, 35, 35, 35, 35, 37, 30, 30, 30, 30, 30, 30, 30
};
const uint8_t ff_aac_num_swb_128[] = {
@@ -1921,20 +1921,24 @@ const uint16_t * const ff_swb_offset_768[] = {
swb_offset_768_8
};
+/**
+ * ISO/IEC 14496-3 defines LD/ELD bands for 22.05-48 kHz only. Other rates
+ * reuse the nearest defined table, as the FDK AAC decoder does.
+ */
const uint16_t * const ff_swb_offset_512[] = {
- NULL, NULL, NULL,
+ swb_offset_512_48, swb_offset_512_48, swb_offset_512_48,
swb_offset_512_48, swb_offset_512_48, swb_offset_512_32,
- swb_offset_512_24, swb_offset_512_24, NULL,
- NULL, NULL, NULL,
- NULL
+ swb_offset_512_24, swb_offset_512_24, swb_offset_512_24,
+ swb_offset_512_24, swb_offset_512_24, swb_offset_512_24,
+ swb_offset_512_24
};
const uint16_t * const ff_swb_offset_480[] = {
- NULL, NULL, NULL,
+ swb_offset_480_48, swb_offset_480_48, swb_offset_480_48,
swb_offset_480_48, swb_offset_480_48, swb_offset_480_32,
- swb_offset_480_24, swb_offset_480_24, NULL,
- NULL, NULL, NULL,
- NULL
+ swb_offset_480_24, swb_offset_480_24, swb_offset_480_24,
+ swb_offset_480_24, swb_offset_480_24, swb_offset_480_24,
+ swb_offset_480_24
};
const uint16_t * const ff_swb_offset_128[] = {
@@ -1980,11 +1984,11 @@ const uint8_t ff_tns_max_bands_usac_1024[] = {
};
const uint8_t ff_tns_max_bands_512[] = {
- 0, 0, 0, 31, 32, 37, 31, 31, 0, 0, 0, 0, 0
+ 31, 31, 31, 31, 32, 37, 31, 31, 31, 31, 31, 31, 31
};
const uint8_t ff_tns_max_bands_480[] = {
- 0, 0, 0, 31, 32, 37, 30, 30, 0, 0, 0, 0, 0
+ 31, 31, 31, 31, 32, 37, 30, 30, 30, 30, 30, 30, 30
};
const uint8_t ff_tns_max_bands_128[] = {
--
2.54.1
>From 553a7e83e1b85c099996e938672fadbc0309f162 Mon Sep 17 00:00:00 2001
From: alexdonzel <[email protected]>
Date: Thu, 19 Nov 2026 15:30:32 +0000
Subject: [PATCH 2/2] fate/aac: add test for 16 kHz AAC-ELD with 480 sample
frames
The sample aac/aac_eld_16k_480.ts (5640 bytes) and its reference
aac/aac_eld_16k_480.s16 need to be added to the FATE suite.
Signed-off-by: alexdonzel <[email protected]>
---
tests/fate/aac.mak | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tests/fate/aac.mak b/tests/fate/aac.mak
index be0420d9519..b0e7b6441ed 100644
--- a/tests/fate/aac.mak
+++ b/tests/fate/aac.mak
@@ -320,6 +320,12 @@ FATE_AAC_LATM += fate-aac-latm_stereo_to_51
fate-aac-latm_stereo_to_51: CMD = pcm -i
$(TARGET_SAMPLES)/aac/latm_stereo_to_51.ts -channel_layout 5.1
fate-aac-latm_stereo_to_51: REF = $(SAMPLES)/aac/latm_stereo_to_51_ref.s16
+# 16 kHz mono AAC-ELD with 480 sample frames, as used by HomeKit cameras;
+# encoded and decoded (for the reference) with FDK AAC
+FATE_AAC_LATM += fate-aac-latm_eld_16k_480
+fate-aac-latm_eld_16k_480: CMD = pcm -i
$(TARGET_SAMPLES)/aac/aac_eld_16k_480.ts
+fate-aac-latm_eld_16k_480: REF = $(SAMPLES)/aac/aac_eld_16k_480.s16
+
fate-aac-autobsf-adtstoasc: CMD = transcode "aac"
$(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
matroska "-c:a copy" "-c:a copy"
--
2.54.1
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]