-
Notifications
You must be signed in to change notification settings - Fork 178
Description
Objective:
Determine if an input <audiobook>.m4b
(i.e., "$m4bin"
) has a chapter index that can be split into constituent chapters or if I should split it into n=threads unindexed pieces for transcoding.
Previous method:
if mediainfo "$m4bin"|grep -q Menu\ \#
worked until it didn't (actually, it's likely I never noticed it failing to detect the presence of chapters until the unindexed split failed for other reasons). The mediainfo outputs will follow.
Potential workaround:
I think that if mediainfo "$m4bin"|grep -Eq ^Menu\ For\|^Menu\ \#
will work here, but I'm worried that what I'm grepping for isn't going to consistently be true for .m4bs with chapter indices and—probably more importantly—consistently false for ones without them. (Also, it feels like so many Ptolemaic epicycles.)
I've not been able to find a way to determine consistently with MediaInfo the presence or absence of a chapter index to branch for processing the audio file to transcode.
Other solutions considered:
In terms of other options I'm considering is to replace the mediainfo call with
if (( $(ffprobe -i "$m4bin" -show_chapters -loglevel error | grep -c '\[CHAPTER\]') > 1 ))
Additional context:
$ mediainfo --version; uname -a
MediaInfo Command line,
MediaInfoLib - v25.04.20250702
Linux 6.15.1-061501-generic #202506041425 SMP PREEMPT_DYNAMIC Wed Jun 4 18:01:32 UTC 2025 x86_64 GNU/Linux
A "normal" chapter index reported by MediaInfo:
$ mediainfo file1.m4b
⋮
Menu #1
ID : 3
Format : Timed Text
Codec ID : text
Duration : 4 h 10 min
Language : English
Menu For : 2
00:00:00.000 : Introduction
00:10:36.000 : Chapter 1
00:35:01.000 : Chapter 2
01:01:53.000 : Chapter 3
01:27:33.000 : Chapter 4
01:46:33.000 : Chapter 5
02:08:44.000 : Chapter 6
02:29:44.000 : Chapter 7
02:49:44.000 : Chapter 8
03:11:28.000 : Chapter 9
03:30:47.000 : Chapter 10
03:52:52.000 : Chapter 11
04:05:23.000 : Chapter 12
Menu #2
00:00:00.000 : Introduction
00:10:36.000 : Chapter 1
00:35:01.000 : Chapter 2
01:01:53.000 : Chapter 3
01:27:33.000 : Chapter 4
01:46:33.000 : Chapter 5
02:08:44.000 : Chapter 6
02:29:44.000 : Chapter 7
02:49:44.000 : Chapter 8
03:11:28.000 : Chapter 9
03:30:47.000 : Chapter 10
03:52:52.000 : Chapter 11
04:05:23.000 : Chapter 12
An "abnormal" chapter index which prompted this:
$ mediainfo file2.m4b
⋮
Menu
ID : 2
Format : Timed Text
Codec ID : text
Duration : 14 h 16 min
Language : English
Encoded date : 2025-08-08 00:03:06 UTC
Tagged date : 2025-08-08 00:03:06 UTC
Menu For : 1
mdhd_Duration : 51413948
00:00:00.000 : Chapter 1
00:00:19.573 : Chapter 2
00:23:47.909 : Chapter 3
00:54:45.064 : Chapter 4
01:09:45.557 : Chapter 5
01:34:25.318 : Chapter 6
01:56:34.637 : Chapter 7
02:04:08.865 : Chapter 8
02:33:59.355 : Chapter 9
03:00:26.113 : Chapter 10
03:19:17.992 : Chapter 11
03:41:10.290 : Chapter 12
04:05:42.040 : Chapter 13
04:33:06.895 : Chapter 14
04:56:34.302 : Chapter 15
05:05:21.557 : Chapter 16
05:30:25.258 : Chapter 17
05:56:34.810 : Chapter 18
06:16:36.465 : Chapter 19
06:22:33.704 : Chapter 20
06:47:10.260 : Chapter 21
07:12:39.108 : Chapter 22
07:31:23.836 : Chapter 23
07:50:01.342 : Chapter 24
08:23:15.820 : Chapter 25
08:47:48.754 : Chapter 26
09:10:37.268 : Chapter 27
09:32:21.532 : Chapter 28
09:50:56.600 : Chapter 29
10:14:03.272 : Chapter 30
10:26:21.596 : Chapter 31
10:51:34.027 : Chapter 32
11:19:08.704 : Chapter 33
11:57:09.762 : Chapter 34
12:56:53.181 : Chapter 35
13:30:23.727 : Chapter 36
13:43:34.087 : Chapter 37
14:15:53.394 : Chapter 38