[Bug]: Chapters not correctly retrieved from multi-m4b books #1622

Closed
opened 2026-04-24 23:52:20 +02:00 by adam · 7 comments
Owner

Originally created by @MikeBishop on GitHub (Dec 28, 2023).

Describe the issue

Obviously this is a niche scenario, but I have a book which is packaged as three m4bs (Graphic Audio, three volumes). ABS is correctly retrieving the Chapter list from the first file, but is ignoring the other two files:
image

Steps to reproduce the issue

  1. Take multiple m4bs which contain chapters
  2. Place them in a single folder in an ABS library
  3. Check the chapter boundaries compared to the file durations

Audiobookshelf version

2.7.0

How are you running audiobookshelf?

Docker

Originally created by @MikeBishop on GitHub (Dec 28, 2023). ### Describe the issue Obviously this is a niche scenario, but I have a book which is packaged as three m4bs (Graphic Audio, three volumes). ABS is correctly retrieving the Chapter list from the first file, but is ignoring the other two files: ![image](https://github.com/advplyr/audiobookshelf/assets/4273797/c8c0dfaa-53bb-4f01-93b2-36c0ec64a4f2) ### Steps to reproduce the issue 1. Take multiple m4bs which contain chapters 2. Place them in a single folder in an ABS library 3. Check the chapter boundaries compared to the file durations ### Audiobookshelf version 2.7.0 ### How are you running audiobookshelf? Docker
adam added the bug label 2026-04-24 23:52:20 +02:00
adam closed this issue 2026-04-24 23:52:21 +02:00
Author
Owner

@nichwall commented on GitHub (Dec 28, 2023):

Possibly related to issue https://github.com/advplyr/audiobookshelf/issues/1999

At one point there was a discussion about how metadata is only extracted from the first media file, but I don't remember where that conversation was or if the behavior has changed with the scanner rewrite beginning in 2.5.0.

@nichwall commented on GitHub (Dec 28, 2023): Possibly related to issue https://github.com/advplyr/audiobookshelf/issues/1999 At one point there was a discussion about how metadata is only extracted from the first media file, but I don't remember where that conversation was or if the behavior has changed with the scanner rewrite beginning in 2.5.0.
Author
Owner

@advplyr commented on GitHub (Dec 28, 2023):

This is related to https://github.com/advplyr/audiobookshelf/issues/1097

The way it works is if there are multiple audio files that have embedded chapters then the chapters will be merged. The chapter times are offset based on the previous audio files duration.

In some cases a multi-track audiobook will include all of the chapters in all of the audio files so when merging them we would get a bunch of duplicate chapters. That was the problem the first time I built out the chapter merge feature.

To mitigate that it checks if all of the chapter titles are the same between the first 2 audio files. If all the chapter titles in the first audio file match the second audio file then only the chapters from the first audio file are used. This is what I think is happening in your case.

Here is the relevant code block that handles merging chapters
https://github.com/advplyr/audiobookshelf/blob/fbbceddba83d196b5036aea9b4edaf25ca554add/server/scanner/AudioFileScanner.js#L464-L496

@advplyr commented on GitHub (Dec 28, 2023): This is related to https://github.com/advplyr/audiobookshelf/issues/1097 The way it works is if there are multiple audio files that have embedded chapters then the chapters will be merged. The chapter times are offset based on the previous audio files duration. In some cases a multi-track audiobook will include all of the chapters in all of the audio files so when merging them we would get a bunch of duplicate chapters. That was the problem the first time I built out the chapter merge feature. To mitigate that it checks if all of the chapter titles are the same between the first 2 audio files. If all the chapter titles in the first audio file match the second audio file then only the chapters from the first audio file are used. This is what I think is happening in your case. Here is the relevant code block that handles merging chapters https://github.com/advplyr/audiobookshelf/blob/fbbceddba83d196b5036aea9b4edaf25ca554add/server/scanner/AudioFileScanner.js#L464-L496
Author
Owner

@MikeBishop commented on GitHub (Dec 29, 2023):

Ah, and because each part names them "Chapter One" and so on, there's no variation. Would it be worth checking that the chapters also have the same length when probing for equality, perhaps?

In the meantime, I can manually rename chapters and rescan. (Or just combine the files.)

@MikeBishop commented on GitHub (Dec 29, 2023): Ah, and because each part names them "Chapter One" and so on, there's no variation. Would it be worth checking that the chapters also have the same length when probing for equality, perhaps? In the meantime, I can manually rename chapters and rescan. (Or just combine the files.)
Author
Owner

@advplyr commented on GitHub (Dec 31, 2023):

Yeah for sure. I just updated this for the next release I'm doing soon.

@advplyr commented on GitHub (Dec 31, 2023): Yeah for sure. I just updated this for the next release I'm doing soon.
Author
Owner

@advplyr commented on GitHub (Dec 31, 2023):

Fixed in v2.7.1

@advplyr commented on GitHub (Dec 31, 2023): Fixed in [v2.7.1](https://github.com/advplyr/audiobookshelf/releases/tag/v2.7.1)
Author
Owner

@nxthor commented on GitHub (Jan 18, 2025):

Hi there!
I stumbled about this while searching around for my same problem:

  • on Version 2.17.7 (docker)
  • a book with 3 files just has the chapters from the first file uploaded
  • the three files have different named chapters, and only the chapters of that file (checked with fre:ac)
    I think this is due to uploading the books one after another? According to the debug log I got three messages about taking chapters from one (first) file after each upload, and maybe this ignores the present data from earlier uploads?

Initially I had to use multiple files because of some limit about the atom in the metadata of one m4b file (?). Files of a size around 1.4GB and higher (maybe size in length, frames or number of chapters?) would upload, but never make it into the DB because the scan would fail.

I will look around in the code I guess, but wanted to drop of this scenario here,
cheers!

@nxthor commented on GitHub (Jan 18, 2025): Hi there! I stumbled about this while searching around for my same problem: * on Version 2.17.7 (docker) * a book with 3 files just has the chapters from the first file uploaded * the three files have different named chapters, and only the chapters of that file (checked with fre:ac) I think this is due to uploading the books one after another? According to the debug log I got three messages about taking chapters from one (first) file after each upload, and maybe this ignores the present data from earlier uploads? Initially I had to use multiple files because of some limit about the atom in the metadata of one m4b file (?). Files of a size around 1.4GB and higher (maybe size in length, frames or number of chapters?) would upload, but never make it into the DB because the scan would fail. I will look around in the code I guess, but wanted to drop of this scenario here, cheers!
Author
Owner

@advplyr commented on GitHub (Jan 18, 2025):

Chapters are set on the initial scan. If you want to scan in chapters again you can delete them on the edit chapters page and then press re-scan in the edit item modal

@advplyr commented on GitHub (Jan 18, 2025): Chapters are set on the initial scan. If you want to scan in chapters again you can delete them on the edit chapters page and then press re-scan in the edit item modal
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1622