mp4write: resolve container timing, HE-AAC rate, and gapless bugs - #179
Merged
Conversation
nschimme
marked this pull request as draft
August 27, 2026 02:34
nschimme
force-pushed
the
add-edts-elst
branch
2 times, most recently
from
August 27, 2026 04:01
c7a5565 to
7b8ce63
Compare
Contributor
Author
|
@fabiangreffrath hold off on a release please, I might need to adjust the ABI contract to fix a flushing bug exposed by gapless media playback. This is also why I submitted some PRs to |
nschimme
force-pushed
the
add-edts-elst
branch
from
August 27, 2026 18:14
7b8ce63 to
07f4203
Compare
nschimme
marked this pull request as ready for review
August 27, 2026 18:17
Contributor
Author
|
Whew, the ABI change wasn't necessary and I was able to resolve it in #180 :-) |
nschimme
force-pushed
the
add-edts-elst
branch
from
August 27, 2026 18:56
07f4203 to
4cc2059
Compare
nschimme
marked this pull request as draft
August 27, 2026 19:11
- Declare HE-AAC container at core sample rate for implicit SBR. - Track real per-frame durations in stts via run-length table instead of guessing. - Add edts/elst edit list atoms for accurate gapless audio trimming. - Fix total output sample calculation (use frame_size instead of priming).
nschimme
force-pushed
the
add-edts-elst
branch
from
August 27, 2026 20:06
4cc2059 to
6897561
Compare
nschimme
marked this pull request as ready for review
August 27, 2026 20:20
Contributor
Author
|
@fabiangreffrath I fixed the bugs, this is ready for merge now |
Contributor
Author
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 PR resolves several critical MP4 container bug fixes and specification compliance issues in
mp4writeandencode_engine.c.It addresses an HE-AAC sample rate declaration bug that caused double-speed playback, replaces fixed-duration guesses in
sttswith dynamic run-length tracking (fixingffmpegdemuxer rejection on short files), adds native edit lists (edts/elst) for gapless playback, and fixes an underlying gapless padding calculation.Key Changes
HE-AAC Core Sample Rate Declaration:
mp4_set_format()to register HE-AAC containers at the core (pre-SBR) rate (sample_rate / 2), matching standard player conventions for implicit SBR signaling.rate_conv_tto scale frame durations from cumulative sample positions and align gapless priming/padding metadata without per-frame rounding drift.Dynamic
sttsDuration Tracking:sttswith a dynamic run-length(count, delta)array (g_mp4.durs).sttsandmdhdthat previously causedffmpegto reject short files ("missing mandatory atoms").Gapless Edit Lists (
edts/elst) & Padding Calculation:edts/elstatom generation when encoder delay is present so ISO-compliant demuxers trim priming samples correctly.total_output_samplesinencode_engine.cto calculate frame totals usingframe_sizeinstead ofpriming(encoder delay), preventing invalid padding values on HE-AAC/SBR streams.Testing & Verification
ffmpeg.ffmpeg -iparses the file without mandatory atom or timing mismatch errors.elstatoms usingmp4box -info/ffprobeto ensure sample-accurate trimming at track boundaries.