Skip to content

fix(android): keep a trimmed WAV extraction exact, release 2.22.0 - #228

Merged
hm21 merged 3 commits into
stablefrom
fix/android-wav-exact-trim
Oct 3, 2026
Merged

hm21 merged 3 commits into
stablefrom
fix/android-wav-exact-trim

Conversation

@hm21

@hm21 hm21 commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Description

A trimmed WAV extraction on Android came out short and shifted: ~70 ms for AAC-LC, over 100 ms for HE-AAC. The AAC decoder drops the encoder delay and padding counted from wherever it starts, so after a seek it threw away real audio instead of the priming.

The decoder now keeps priming and padding, and the range is cut from its output on the audio's own timeline. Both ways an MP4 can declare the delay are handled: iTunes metadata (first sample at 0) and an edit list (first sample before 0, as ffmpeg writes it).

Measured on a Galaxy S942B with clips whose bursts start at exactly 0.6 s and 1.2 s:

before after
AAC-LC, trim 0.5–1.5 s 932 ms, bursts 11 ms early 1000 ms, exact
HE-AAC v1/v2, trim 0.5–1.5 s 885 ms, bursts 11 ms early 1000 ms, exact
ffmpeg AAC, trim 0.5–1.5 s 975 ms, bursts 34 ms early 1000 ms, exact
ffmpeg AAC, full 2020 ms 2000 ms

macOS gives the same numbers. MP3 trims now have the exact length but are still ~52 ms early: after a seek the MP3 decoder discards two frames and stamps its output by sample count. That was already the case before (75 ms early and short).

Found while testing #225, whose new HE-AAC test fails on Android without this.

Tests

  • New extractAudio to WAV keeps a trimmed range in place (two ~5 KB AAC clips); fails on stable, passes on Android and macOS.
  • Galaxy: audio_extract, audio_track_trim, audio_fade, audio_merge, clip_volume_custom_audio, layered_composition_audio, all green; JVM unit tests green.

Type of Change

  • 🛠️ Bug fix (non-breaking change which fixes an issue)

The AAC decoder drops the encoder delay and padding counted from wherever
it starts, so after a seek it dropped real audio instead: a trimmed WAV
came out ~70 ms short for AAC and over 100 ms for HE-AAC, and shifted.
The decoder now keeps them and the range is cut from its output on the
audio's own timeline, honouring both ways an MP4 declares the delay
(iTunes metadata, edit list). A test checks length and burst positions
for full and trimmed extractions.
@hm21 hm21 changed the title fix(android): keep a trimmed WAV extraction exact fix(android): keep a trimmed WAV extraction exact, release 2.22.0 Oct 3, 2026
@hm21
hm21 merged commit 0d489f0 into stable Oct 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant