PR #26201 opened by Romain Beauxis (toots)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26201
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26201.patch

`mov_fix_index` counts the samples an edit list skips in the track's clock, but 
they are read at the sample rate. HE-AAC with explicit SBR often keeps the 
clock at the core rate, so an edit starting mid-packet kept the samples before 
it (128 per channel on an fdkaac sample with its edit moved by 64 core ticks). 
The count is now rescaled for AAC whose sample rate is above the clock.

`fate-mov-aac-he-core-rate-priming` checks `initial_padding` on an existing 
fdkaac HE-AAC sample: 2048 before, 4096 after.


>From 5e767bddb9266c8239c0c27a768ea87fd062fffe Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Thu, 19 Nov 2026 07:51:33 -0600
Subject: [PATCH 1/2] tests/fate/mov: add a test for HE-AAC priming on a
 core-rate clock

The track clock is the 22050 Hz core rate; the edit list skips 2048
ticks, 4096 output samples.
---
 tests/fate/mov.mak                          | 4 ++++
 tests/ref/fate/mov-aac-he-core-rate-priming | 1 +
 2 files changed, 5 insertions(+)
 create mode 100644 tests/ref/fate/mov-aac-he-core-rate-priming

diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index a603ca94dec..ab7cfc74668 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -168,6 +168,10 @@ fate-mov-aac-2048-priming-preroll: CMD = run 
ffprobe$(PROGSSUF)$(EXESUF) -show_e
 FATE_MOV_FFPROBE-$(call DEMDEC, MOV, AAC) += 
fate-mov-aac-2048-priming-seek-landing
 fate-mov-aac-2048-priming-seek-landing: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-seek_flags preroll -read_intervals 2.3%+\#3 -show_entries 
packet=pts,dts,duration -print_format compact 
$(TARGET_SAMPLES)/mov/aac-2048-priming.mov
 
+# HE-AAC whose track clock is the core rate, half the output rate.
+FATE_MOV_FFPROBE-$(call DEMDEC, MOV, AAC) += fate-mov-aac-he-core-rate-priming
+fate-mov-aac-he-core-rate-priming: CMD = run ffprobe$(PROGSSUF)$(EXESUF) 
-show_entries stream=sample_rate,time_base,initial_padding -print_format 
compact $(TARGET_SAMPLES)/audiomatch/tones_fdkaac_44100_stereo_aac_he.m4a
+
 # Seeking into the stream must not drop samples to the container's priming.
 FATE_MOV-$(call FRAMECRC, MOV, AAC, PCM_S16LE_ENCODER ARESAMPLE_FILTER 
VOLUME_FILTER) += fate-mov-aac-2048-priming-seek
 fate-mov-aac-2048-priming-seek: CMD = framecrc -ss 2.3 -t 0.15 -i 
$(TARGET_SAMPLES)/mov/aac-2048-priming.mov -af volume=0,aresample -c:a pcm_s16le
diff --git a/tests/ref/fate/mov-aac-he-core-rate-priming 
b/tests/ref/fate/mov-aac-he-core-rate-priming
new file mode 100644
index 00000000000..8e1fceace25
--- /dev/null
+++ b/tests/ref/fate/mov-aac-he-core-rate-priming
@@ -0,0 +1 @@
+stream|sample_rate=44100|initial_padding=2048|time_base=1/22050
-- 
2.54.1


>From 77f202490e32e96195df32abcbd2a9d6d1154459 Mon Sep 17 00:00:00 2001
From: Romain Beauxis <[email protected]>
Date: Thu, 19 Nov 2026 07:55:57 -0600
Subject: [PATCH 2/2] avformat/mov: count the samples an edit list skips at the
 sample rate

mov_fix_index counted them in the track's clock, which for HE-AAC with
explicit SBR is often the core rate, so an edit starting mid-packet
kept the samples before it.
---
 libavformat/mov.c                           | 8 ++++++++
 tests/ref/fate/mov-aac-he-core-rate-priming | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 85936bf8252..199fa40eb39 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4900,6 +4900,14 @@ truncated:
 
     // Update av stream length, if it ends up shorter than the track's media 
duration
     st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts);
+    // The skipped samples are counted in the track's clock. With explicit SBR
+    // signalling, HE-AAC often keeps it at the core rate, half the output
+    // rate. A sample rate below the clock is no output rate: implicit SBR
+    // reports the core rate, and stsd cannot store rates above 65535.
+    if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
+        st->codecpar->sample_rate > msc->time_scale && msc->time_scale > 0)
+        sti->skip_samples = FFMIN(av_rescale(sti->skip_samples, 
st->codecpar->sample_rate,
+                                             msc->time_scale), INT_MAX);
     st->codecpar->initial_padding = sti->skip_samples;
 
     // Free the old index and the old CTTS structures
diff --git a/tests/ref/fate/mov-aac-he-core-rate-priming 
b/tests/ref/fate/mov-aac-he-core-rate-priming
index 8e1fceace25..58874d795ad 100644
--- a/tests/ref/fate/mov-aac-he-core-rate-priming
+++ b/tests/ref/fate/mov-aac-he-core-rate-priming
@@ -1 +1 @@
-stream|sample_rate=44100|initial_padding=2048|time_base=1/22050
+stream|sample_rate=44100|initial_padding=4096|time_base=1/22050
-- 
2.54.1

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

Reply via email to