Open archisman-panigrahi opened 3 years ago
The m4b file above stores the chapter data in a separate track that contains 21 media samples that point to the chapters buried in the mdat atom. (Rather than the recommended way of using the chap atom in the meta data.) Looks like an old shareware app
So I think the thing to do is look for a second Track with codec of type text.. and then look at the media atom and look at the 21 samples, one for each chapter. Hopefully will point to the chapter data.
You can look for another mp4 parsing app that can handle those chapters and see how they do it. I found a nodejs/typescript project that looks promising as the comments show similar issues with chapter decoding: https://github.com/Borewit/music-metadata
Hopefully I'll dig in a little deeper.
This issue is quite prevalent. It's especially significant for files such as audio books or live concerts, which often don't split into separate tracks.
Regardless of whether they're using an outdated method to mark the chapters, m4b files are still being produced very recently with undetected hidden chapters. The file linked earlier was just a public domain example from an open library, but I've seen many instances of this issue with brand new works.
For reference, I've tried many music/audio players, and the only ones which have detected chapters consistently is qmmp
and vlc
(although VLC had tracking bugs, so it's also unsuitable for mp4 audiobooks)
If there is no fix here, I have a workaround: for each book affected, use m4b-tool to export chapters to a text file and then import them into the original file. I would recommend you back up the audiobook files first, as this does edit them, and use the prerelease.
mutagen-inspect [filename].m4b
m4b-tool meta --export-chapters=[filename].chapters.txt [filename].m4b
m4b-tool meta --import-chapters=[filename].chapters.txt [filename].m4b
mutagen-inspect [filename].m4b
Upon doing this with this book, the chapters populated in mutagen-inspect
.
Steps to reproduce:
Download the m4b file of Tales from Shakespeare from LibriVox (it is in the public domain).
Programs using the mutagen library cannot detect the chapters, but VLC player can detect them.
Related comment: https://github.com/geigi/cozy/issues/547#issuecomment-886193281