Open RayBB opened 5 years ago
Thanks for your kinds words! Let me see if I can check this during the week :).
I looked into this and after inspecting the file I noticed the chapter information lies within the moov.trak.tref.chap
atom. I was not expecting this, this library only reads the moov.udta.meta
atom where all the metadata resides.
I search a bit online and found that it is the Quicktime Chapters format that is stored in a very similar fashion to subtitles: https://github.com/Zeugma440/atldotnet/wiki/Focus-on-Chapter-metadata#quicktime-qt-chapters
The Nero Chapters, which is another format, are actually stored in moov.udta
and includes the starting time of the chapter.
The QT do not and forces you to read the samples in a non-trivial way to get to the name of each chapter.
The way MP4 support is implemented is extermly naive right now, we just go down the tree of atoms and find the first one that matches the metadata. I’m surprised it has been working since this only works if the metadata happens to be the first one in the tree as we don’t backtrack.
To implement this we need:
I may add this to music-metadata. I hope you don't mind @aadsm.
@Borewit that would be great please do! I’m half way through but ended up not having the time to finish it yet.
Very nice. Traversing the atoms is pretty tricky, lots of corner cases. I will be busy to coming few weeks, effort may need to wait a bit on my end as well.
Update #302: It's a complex operation to extract the chapters. The information appears not to be directly embedded in the chap
atom. This only a tiny atom holding a pointer to another track which contains the chapter information. The actual information (the chapter titles) are encoded in the raw data stream (payload of mdat
atom) divided in small chunks, just before the content chunks kicks in. Extracting that from the mdat
has been a true challenge. The next challenge was to attach the corresponding offsets to the chapters to understand where they start.
I implemented extracting of MP4 chapter in music-metadata v5.0.0. I am looking to forward for your feedback @RayBB.
@Borewit this is great, but might be a good idea to move this discussion to the appropriate project github page?
First, I want to say thanks so much for creating and maintaining this awesome library! It works quite well and doesn't seem like it was easy to write.
Anyway, I was wondering if it's possible to add support for M4B chapters / bookmarks? I see that there should be support for MP4 but when I try to run this with my M4B file it isn't picking up the chapters (though
ffmpeg -i
does).My understanding was that MP4 and M4B bookmark formats should be very similar.
If you would like a M4B file to test with you can try this (downloaded from here)
Any help with this would be greatly appreciated! :) I'm thinking of building an open source web-based audiobook player and detecting chapters would be very helpful for this.