quodlibet / mutagen

Python module for handling audio metadata
https://mutagen.readthedocs.io
GNU General Public License v2.0
1.56k stars 158 forks source link

No chapters are detected in certain m4b files #530

Open archisman-panigrahi opened 3 years ago

archisman-panigrahi commented 3 years ago

Steps to reproduce:

  1. Download the m4b file of Tales from Shakespeare from LibriVox (it is in the public domain).

  2. 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

openaudible commented 2 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.

jeois commented 1 year ago

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)

LSeelig commented 2 months ago

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.