Repository navigation
fix(mp4): preserve duplicate trak boxes during tag rewrite - #14
Merged
Merged
Conversation
Build the fallback MP4 output from the complete edited moov instead of iterating NodeBox.replaceBox per child. replaceBox removes every child with the same fourcc, so replacing trak boxes individually leaves only the final track and produces a truncated file without playable audio. - ReplaceMP4Editor.copy: construct new Movie from source ftyp/others + the fully-edited moov (includes all trak boxes) - RelocateMP4Editor.relocate: clear + addAll instead of per-box replaceBox — same duplicate-fourcc loss (e.g. soun/odsm/sdsm in M4B) - Add regression test testGrowingTagPreservesAllTracks (test16.m4a: soun, odsm, sdsm) that forces the grow-path via a large comment Fixes #13 Supersedes #13 Co-authored-by: Marcelwalter <36072734+Marcelwalter@users.noreply.github.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Aug 30, 2026
## [2.0.31](2.0.30...2.0.31) (2026-08-30) ### Bug Fixes * **ci:** install missing semantic-release plugins for release ([a683f31](a683f31)) * **ci:** pin conventional-changelog-conventionalcommits to v9 ([2a89302](2a89302)) * **mp4:** preserve duplicate trak boxes during tag rewrite ([#14](#14)) ([03bb24b](03bb24b)), closes [#13](#13) [#13](#13)
Owner
Author
|
🎉 This PR is included in version 2.0.31 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Summary
Extends #13 to also fix the same duplicate-
trakloss inRelocateMP4Editor.moov(new Movie(source.getFtyp(), edit, source.getOthers())) instead of iteratingNodeBox.replaceBoxper child.clear() + addAllinstead of per-boxreplaceBox— same root cause (see below).testGrowingTagPreservesAllTracks(from fix: preserve MP4 tracks during tag rewrite #13) covering audio + chapter/data tracks.Closes #13
Supersedes #13 — includes original fix by @Marcelwalter, adds Relocate patch and keeps attribution via Co-authored-by.
Why
NodeBox.replaceBox(Box)doesremoveChildren(fourcc) + add(box). Replacingtrakboxes individually therefore removes everytrakeach iteration and leaves only the final track. For multi-track MP4/M4B (e.g.soun/odsm/sdsmchapter files) the fallback write path produces a much smaller file without playable audio.Both editors had the same loop:
This PR fixes both:
ReplaceMP4Editor(fallback viaFlatten) — the reported pathRelocateMP4Editor(fallback viawriteMoviewhen moov is relocated to EOF)InplaceMP4Editor.modifyalready usesclear()+addAlland is not affected.Testing
./mvnw -Dtest=org.jaudiotagger.tag.mp4.M4aWriteTagTest#testGrowingTagPreservesAllTracks— pass./mvnw -Dtest=org.jaudiotagger.tag.mp4.M4aWriteTagTest— 31 tests passed (30 + new)Credits
Original diagnosis, fix and test by @Marcelwalter in #13 — retained here with
Co-authored-by. Relocate fix added in this PR.Fixes #13