frontend: add sample-accurate gapless MP4 decoding - #238
Merged
fabiangreffrath merged 1 commit intoAug 27, 2026
Conversation
Implement sample-accurate MP4 gapless trimming via 'elst' edit lists
and 'iTunSMPB' metadata tags.
- Dynamic frame-size trimming: Use ASC 'framesize' for front-trim
calculation instead of a fixed 1024-sample offset.
- Implicit SBR rate rescaling: Rescale delay and valid sample counts
when container timescale matches the core rate rather than output rate.
- Fix `-g` flag parsing and harden MP4 metadata atom parsing ('hdlr', '----').
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a new feature to ease automated regression testing and eliminate extra padding that reference .wav files didn't have.
This PR adds sample-accurate gapless MP4 trimming via
elstedit lists (with fallback toiTunSMPBmetadata tags), fixes-gflag parsing, and hardens MP4 metadata atom handling.It incorporates two critical rate-domain fixes discovered during reference testing against FFmpeg and Apple's AudioToolbox (
afconvert):net_start_trim = gapless_delay - 1024) with the actualframesizecalculated from the Audio Specific Config (ASC). The fixed 1024 offset was causing 1-frame over-trimming on SBR/HE-AAC streams.gapless_delayand valid sample counts when container timescales match the core (pre-SBR) rate rather than the output rate. This resolves output truncation on files authored viafdkaacorafconvert.Verification & Proof of Safety
Trim boundaries were verified for sample accuracy by decoding test files from multiple encoders across
faad2,ffmpeg, and Apple'safconvert, then measuring sample counts and RMS alignment against the raw uncompressed source:faad2SamplesffmpegSamplesafconvert*Matches Apple's native sample-rounding behavior.
Key Impact
fdkaac,afconvert) and eliminates the 1-frame over-trim on all SBR streams.Test Checklist
cmake+ninja) on currentmaster.ffmpegfor all encoder/profile permutations.afconvert/aac_atforfdkaacandafconvertfiles.