sandreas / m4b-tool

m4b-tool is a command line utility to merge, split and chapterize audiobook files such as mp3, ogg, flac, m4a or m4b
MIT License
1.14k stars 77 forks source link

macos chapter splitting problem #153

Open skaai opened 2 years ago

skaai commented 2 years ago

First of all, thank you so much for this little app. I really love using it to split and edit my own m4b files and was even thinking of toying with adding a gui frontend (because I'm lazy). If I do, I'll let you know, or if one is already out there, let me know! The problem I have is: running the split command splits the file at what seems like silences, instead of splitting it at chapter markers. m4b-tool split --audio-format mp3 --audio-bitrate 128k --audio-channels 2 --audio-samplerate 44100 AUDIOBOOK.m4b I ran this same command on the same audiobook on two different machines (macos 11.5.1 intel & debian 10). The Debian machine splits the audiobook with no issues. The macos machine is the one that splits the file incorrectly. Past history may be informative: Before doing this, I had different problems running m4b-tool but when I upgraded to BigSur I'd get dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicuio.67.dylib   Referenced from: /usr/local/bin/php   Reason: image not found Abort trap: 6 I upgraded php (brew upgrade php) and it currently reports 8.0.7, though at the time this didn't seem to fix the m4b-tool problem. get latest release: In march 26 of this year I went to your "latest releases" page and downloaded the latest (at the time latest-127-gb61f0f8) m4b-tool and ran it. This seemed to work partially: m4b-tool now splits the file, but now complains that extracting cover to AUDIOBOOK.art[0].jpg failed - maybe there was no cover embedded in AUDIOBOOK.m4b despite the fact it was embedded. For a while, I was happy it at least worked at splitting, though I'd get a few hundred files and had to join them in other apps. try again, ffmpeg complains too: In August 30 of this year, I decided to attack the problem again and downloaded the latest (latest-137-g14781fb) and ran the split command again. This time, it generated two errors: ffmpeg version 4.0.0 or higher is required - installed version 2.0.5 is likely to cause errors or unexpected behaviour... extracting cover to AUDIOBOOK.art[0].jpg failed - maybe there was no cover embedded in AUDIOBOOK.m4b Why it complains about my ffmpeg I do not know, since I followed your instructions to add the libfdk_aac, as evidenced by the response when I run "brew list --versions ffmpeg" and get ffmpeg 4.4-with-options_1 Typing the command: [ -x "$(which ffmpeg)" ] && (ffmpeg -hide_banner -codecs 2>&1 | grep libfdk || brew uninstall ffmpeg) produces this result: DEAIL. aac AAC (Advanced Audio Coding) (decoders: aac aac_fixed aac_at libfdk_aac ) (encoders: aac aac_at libfdk_aac ) Typing "ffmpeg -version" generates this large output: ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers built with Apple clang version 12.0.5 (clang-1205.0.22.11) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4-with-options_1 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --disable-libjack --disable-indev=jack --enable-opencl --enable-videotoolbox --disable-htmlpages --enable-libfdk-aac --enable-openssl --enable-nonfree libavutil 56. 70.100 / 56. 70.100 libavcodec 58.134.100 / 58.134.100 libavformat 58. 76.100 / 58. 76.100 libavdevice 58. 13.100 / 58. 13.100 libavfilter 7.110.100 / 7.110.100 libswscale 5. 9.100 / 5. 9.100 libswresample 3. 9.100 / 3. 9.100 libpostproc 55. 9.100 / 55. 9.100 other troubleshooting steps: I also read this thread with someone who had a similar php problem and later also had a problem with chapters (coincidence?) and you told him to run the --use-existing-chapters command.

  1. running the UEC command on the file alone: behavior unchanged
  2. extracting the chapters.txt file and running UEC on the file: behavior unchanged
  3. removing the first line of the chapters.txt file (because your guide on adding chapters did not include the first line and the extraction did): behavior unchanged.
  4. renaming chapters.txt to AUDIOBOOK.chapters.txt (adding the name of the book to the beginning) because I read somewhere that this was important: behavior unchanged.
  5. moving and renaming the audiobook to a higher folder and renaming it test.m4b (in case the name was too long): behavior unchanged.

my guesses: I think the previous php error may be a clue. Also, I have no other installations of ffmpeg, so I don't even know where m4b-tool is getting the version 2.0.5 from. The failure to extract the embedded cover (when one exists) may be another clue. The fact this same audiobook is successfully extracted in the Debian (v.0.4.2) but the macos 11.5.1 version (latest-137-g14781fb) splits the file at what appear to be silences, and no addition of the chapters file fixes this. The only thing I haven't tested was trying it with a .cue sheet, mostly because I haven't looked into how to convert my text file into a cue sheet. So I hope this helps explain the problem. m4b-tool works wonderfully otherwise, but re-stitching a 240 section file back into 18 chapters is a pain in the neck. thank you again!

sandreas commented 2 years ago

The chapter splitting command seems to need some love (I don't use it very often, so I have to make up some manual tests for this).

To answer your questions:

extracting cover to AUDIOBOOK.art[0].jpg failed - maybe there was no cover embedded in AUDIOBOOK.m4b

If there is a cover embedded, this should work - but there is definetely is an issue, that I have to fix (see below)

Why it complains about my ffmpeg I do not know

This has already been fixed in the source - ffmpeg version detect regex was bogus.

Typing the command ... produces this result: DEAIL. aac AAC (Advanced Audio Coding) ...

This is correct, the little shell command is used to detect, if you already have ffmpeg with libfdk installed, which is true on your system, so only the output appears.

I'll summarize:

To workaround you issue, you could install another m4b-tool version (e.g. 0.4.2), name it m4b-tool-042, to not overwrite the original command and use m4b-tool-042 split --audio-format mp3 --audio-bitrate 128k --audio-channels 2 --audio-samplerate 44100 AUDIOBOOK.m4b

Could you please provide (CAUTION: this might include personal data, that you should remove before):

Thank you.

skaai commented 2 years ago

Thank you for your help, I did what you asked for and a few more steps that I thought you'd find helpful.

  1. m4b-tool meta test: generated a list (see next input)
  2. m4b-tool version: failed (because -v is the only way to get it to report version)
  3. download an earlier version: did 0.4.2 but it failed just like before.
  4. re-ran m4b-tool to see if anything changed: Nope. It works, but generates 225 files.
skaai commented 2 years ago

m4b-tool meta test

[22:58:45]skaai@purplemonkey[test]$: m4b-tool meta test.m4b
ffmpeg version 4.0.0 or higher is required - installed version 2.0.5 is likely to cause errors or unexpected behaviour...
album            : AUDIOBOOK (Unabridged)
albumartist      : author 1, author 2
artist           : author 1, author 2
comment          : some long text that describes the audiobook
copyright        : ©1983, some company
cover            : embedded jpeg, 500x500
encoder          : Lavf58.76.100
genre            : Audiobook
name             : AUDIOBOOK: audiobook subtitle
type             : 2

chapters
# total-length 10:42:24.660
00:00:00.000 Chapter 1
00:11:20.901 Chapter 2
00:32:04.934 Chapter 3
00:47:28.949 Chapter 4
01:03:48.970 Chapter 5
01:21:01.979 Chapter 6
01:42:03.009 Chapter 7
01:59:53.031 Chapter 8
02:19:49.044 Chapter 9
02:39:25.088 Chapter 10
02:59:15.111 Chapter 11
03:19:05.134 Chapter 12
03:39:46.194 Chapter 13
03:57:01.246 Chapter 14
04:11:41.283 Chapter 15
04:28:54.292 Chapter 16
04:50:08.325 Chapter 17
05:05:44.367 Chapter 18
05:21:16.788 Chapter 19
05:38:35.834 Chapter 20
05:38:51.252 Chapter 21
05:58:15.501 Chapter 22
06:14:59.532 Chapter 23
06:33:01.582 Chapter 24
06:46:32.608 Chapter 25
06:59:26.622 Chapter 26
07:13:43.671 Chapter 27
07:29:38.940 Chapter 28
07:43:08.109 Chapter 29
08:03:41.135 Chapter 30
08:23:09.145 Chapter 31
08:38:18.160 Chapter 32
08:52:38.598 Chapter 33
09:15:13.622 Chapter 34
09:35:31.648 Chapter 35
09:47:57.659 Chapter 36
10:02:27.664 Chapter 37
10:20:31.664 Chapter 38

Empty tag fields : description, disk, disks, encoded-by, grouping, language, longdesc, lyrics, performer, publisher, purchaseDate, sortAlbumArtist, sortWriter, sortalbum, sortartist, sortname, track, tracks, writer, year
skaai commented 2 years ago

output of m4b-tool version

[22:59:11]skaai@purplemonkey[test]$: m4b-tool version

  Command "version" is not defined.

[23:02:26]skaai@purplemonkey[test]$: m4b-tool -v
m4b-tool latest-137-g14781fb

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  chapters  Adds chapters to m4b file
  help      Displays help for a command
  list      Lists commands
  merge     Merges a set of files to one single file
  meta      View and change metadata for a single file
  split     Splits an m4b file into parts
[23:02:38]skaai@purplemonkey[test]$:
skaai commented 2 years ago

Downloaded version 0.4.2 but it just generated the same error I had a year ago. I include a screenshot to give an idea of the output I got and how long it took. As you can see, the 0.4.2 fails but the latest latest-137-g14781fb spits out some errors, but splits the file into 225 files instead of the 38 that it should have. My own guess: since the meta shows it sees the chapters, something else must be off in the latest versions (also note, this exact same behavior was happening with latest-127-gb61f0f8 too). terminal_m4btool-16

sandreas commented 2 years ago

Ok, thanks for testing. I'll take a look as soon as possible.

rafdre commented 2 years ago

I have waited for a long time for new version in AUR : https://aur.archlinux.org/packages/m4b-tool-bin Finally its there, but I have issue as described here. "m4b-tool meta 01.m4b" shows chapters as I expect them to be....but when I run split it divides file into several small files (not in the chapters I see when I run "m4b-tool meta 01.m4b". Last lines after I execute '"m4b-tool meta 01.m4b" show me that there is an error:

Empty tag fields : albumartist, comment, copyright, cover, description, disk, disks, encoded-by, grouping, language, longdesc, lyrics, performer, publisher, purchaseDate, sortAlbumArtist, sortWriter, sortalbum, sortartist, sortname, tracks, writer, year
an error occured, that has not been caught:
Array
(
    [type] => 8192
    [message] => trim(): Passing null to parameter #1 ($string) of type string is deprecated
    [file] => phar:///usr/local/bin/m4b-tool/src/library/Command/AbstractCommand.php
    [line] => 420
)

Moreover I do see warning "ffmpeg version 4.0.0 or higher is required - installed version 1.2.0 is likely to cause errors or unexpected behaviour..." even though I do have new version of ffmpeg (see my comment on AUR).

Here m4b-tool version outocome


  Command "version" is not defined.  

an error occured, that has not been caught:
Array
(
    [type] => 8192
    [message] => Return type of Sandreas\Time\TimeUnit::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
    [file] => phar:///usr/local/bin/m4b-tool/vendor/sandreas/php-time/src/Sandreas/Time/TimeUnit.php
    [line] => 241
)
sandreas commented 2 years ago

Thanks for reporting. Currently I'm putting much effort into tone, a C# based tool that should be the successor of m4b-tool in the long term (using the audio library https://github.com/Zeugma440/atldotnet).

Maybe I have some time next week to take a look into this - but if you are on macOS or Linux, I highly recommend using the docker image of m4b-tool, which is preconfigured as good as I could.