From the archives
2021-11-30
Note: This was posted to my old blog. I’m only posting this here so I can finally delete that old abandoned git repo.
In order to better understand the MP4 format and remove dependencies from some of my personal projects I decided to write this MP4 muxer. It won’t parse MP4 files for you, for that you’re on your own. While I do have the code to do that, it doesn’t provide much “coverage” when it comes to all the different ISO standards, so one can’t just throw any kind of MP4 file at it and make it work. Maybe I’ll revisit that at a later date.
Disclaimers: This code will only work for ALAC and EAC3 JOC (Dolby Atmos) streams. Support for AAC is planned, but not exactly a priority right now.
The majority of code is based on various ISO standards along with the information provided by applications such as Mp4Explorer, MediaInfo or ffmpeg/ffprobe in addition to what I was able to figure out by staring at files in HxD for much longer than I would like to admit.
I could have gotten by with ffmpeg and mp4muxer alone had it
not been for the fact that ffmpeg kept dropping samples when using the
-c:a copy
option. It kept messing with the
stts
box for whatever reason and I was never quite able to
figure out why.
In addition to that I wanted to properly implement iTunes-like
metadata, especially for all the tags that made mutagen
break, like AppleStoreCatalogID
or
AlbumTitleID
(even if support is apparently there according
to the docs).
Example MediaInfo output:
Album : Let It Be (2021 Mix)
Album/Performer : The Beatles
Part/Position : 1
Part/Total : 1
Track name : Let It Be (2021 Mix)
Track name/Position : 6
Track name/Total : 12
Performer : The Beatles
Composer : Paul McCartney & John Lennon
Genre : Rock
Recorded date : 1970-05-08
Encoded date : UTC 2021-10-15 02:46:12
Tagged date : UTC 2021-10-15 02:46:12
ISRC : GBUM72006886
Copyright : ℗ 2021 Calderstone Productions Limited (a division of Universal Music Group)
Cover : Yes
AppleStoreCatalogID : 1582223667
PlayListID : 1582219768
AlbumTitleID : 136975
UPC : 00602438575688
LABEL : UMC (Universal Music Catalogue)
Source code for the project one example each for ALAC and EAC3 can be found here: 0x666690/mp4