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.15k stars 76 forks source link

Issue with the split command and PHP_OS_FAMILY #188

Closed MituButChi closed 2 years ago

MituButChi commented 2 years ago

Hi. I finally got the tool up and running after hours of trials and errors cuz I don't know anything about programming and little experience working with audio files. After all I'm glad I managed to make it work.

Now when I'm using the tool, it shows me a message like this:

m4b-tool split --audio-format mp3 --audio-bitrate 96k --audio-channels 1 --audio-samplerate 22050 "C:/m4b-tool/to-split.m4b"
ffmpeg version 4.0.0 or higher is required - installed version 0.2.0 is likely to cause errors or unexpected behaviour...
PHP Notice:  Use of undefined constant PHP_OS_FAMILY - assumed 'PHP_OS_FAMILY' in phar://C:/PHP7/phars/m4b-tool.phar/src/library/Command/AbstractCommand.php on line 371

Notice: Use of undefined constant PHP_OS_FAMILY - assumed 'PHP_OS_FAMILY' in phar://C:/PHP7/phars/m4b-tool.phar/src/library/Command/AbstractCommand.php on line 371
extracting cover to C:/m4b-tool/to-split_splitted/cover.jpg failed - maybe there was no cover embedded in C:/m4b-tool/to-split.m4b
an error occured, that has not been caught:
Array
(
    [type] => 8
    [message] => Use of undefined constant PHP_OS_FAMILY - assumed 'PHP_OS_FAMILY'
    [file] => phar://C:/PHP7/phars/m4b-tool.phar/src/library/Command/AbstractCommand.php
    [line] => 371
)

The split command doesn't work correctly:


The merge command works fine but it also shows the PHP_OS_FAMILY error.

I installed PHP 7.1.32. I added PHP 7.1, phar folder, ffmpeg and mp4v2 to my Environment Variables. I wanted to build docker image like you recommended but I didn't understand anything about the instruction, it's like reading a foreign language. Is that the problem here?

Thank you for creating this tool. I'd really appreciate the help.

sandreas commented 2 years ago

Thank you for reporting this issue... unfortunately, m4b-tool is for power users, so the instructions might be frustrating to read for a person, who is not an expert of command line and linux... I understand that.

But as you provided detailed errors, please let me ask you the following questions:

Probably you are using 0.4.2, which is outdated by far (unfortunately, I did not have the time to provide another release - m4b-tool is a maintainers mess :-). If so, you should upgrade to latest pre-release, see instructions.

I plan to iron out the roughest edges asap, but it will take some time...

The docker image is highly recommended, because it is a preconfigured all in one easy to install VM-ish environment, where you just need one command and you are done... to install docker, you have to follow the instructions for your OS - once installed, it is two commands to get m4b-tool up and running.

MituButChi commented 2 years ago

unfortunately, m4b-tool is for power users, so the instructions might be frustrating to read for a person, who is not an expert of command line and linux...

Yes that applies for a lot of things on GitHub. I've accepted my faith actually, and just try my best. It just takes me a loooooot more time and effort than people with programming expertise.


Sorry I should have specified.

I'll try to find a tutorial for the docker image. In the meantime could you help me with the issue above? Thank you.

MituButChi commented 2 years ago

So after a lot of tutorials, I successfully set up Docker and managed to pulled the m4b-tool.

I couldn't set up the alias though. I tried pasting these in the command prompt, nothing worked.

alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

'alias' is not recognized as an internal or external command, operable program or batch file.

docker alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

unknown shorthand flag: 'i' in -it See 'docker --help'. Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers [...]

I doubt this one is the correct one though.

docker run sandreas/m4b-tool:latest alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt sandreas/m4b-tool:latest'

Unable to find image 'sandreas/mb4-tool:latest' locally docker: Error response from daemon: pull access denied for sandreas/mb4-tool, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'.

I logged in to my Docker Desktop. And I have it running the whole time. The image has a green In Use tag in Docker.

Which is the right command for alias?


So now everytime I run a command, I have to use:

docker run sandreas/m4b-tool merge "M:\audiobooks\audiobook maker\input\" --output-file="M:\merged.m4b"

But it still doesn't work. Here's the error message:

--output-file is required
trace: #0 phar:///usr/local/bin/m4b-tool-pre/vendor/symfony/console/Command/Command.php(255): M4bTool\Command\MergeCommand->execute()
#1 phar:///usr/local/bin/m4b-tool-pre/vendor/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#2 phar:///usr/local/bin/m4b-tool-pre/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#3 phar:///usr/local/bin/m4b-tool-pre/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#4 phar:///usr/local/bin/m4b-tool-pre/bin/m4b-tool.php(47): Symfony\Component\Console\Application->run()
#5 /usr/local/bin/m4b-tool-pre(10): require('...')
#6 {main}

I also tried the split command:

docker run sandreas/m4b-tool split --audio-format mp3 --audio-bitrate 96k --audio-channels 1 --audio-samplerate 22050 "C:\audiobooks\1.m4b"

It says:

In AbstractCommand.php line 390:

  Input is not a file

split [--logfile [LOGFILE]] [--debug] [-f|--force] [--tmp-dir [TMP-DIR]] [--no-cleanup] [--no-cache] [--ffmpeg-threads [FFMPEG-THREADS]] [--platform-charset [PLATFORM-CHARSET]] [--ffmpeg-param [FFMPEG-PARAM]] [-a|--silence-min-length [SILENCE-MIN-LENGTH]] [-b|--silence-max-length [SILENCE-MAX-LENGTH]] [--max-chapter-length [MAX-CHAPTER-LENGTH]] [--name [NAME]] [--sortname [SORTNAME]] [--album [ALBUM]] [--sortalbum [SORTALBUM]] [--artist [ARTIST]] [--sortartist [SORTARTIST]] [--genre [GENRE]] [--writer [WRITER]] [--albumartist [ALBUMARTIST]] [--year [YEAR]] [--description [DESCRIPTION]] [--longdesc [LONGDESC]] [--comment [COMMENT]] [--copyright [COPYRIGHT]] [--encoded-by [ENCODED-BY]] [--grouping [GROUPING]] [--purchase-date [PURCHASE-DATE]] [--encoder [ENCODER]] [--cover [COVER]] [--skip-cover-if-exists] [--skip-cover] [--series [SERIES]] [--series-part [SERIES-PART]] [--remove [REMOVE]] [--ignore-source-tags] [--prefer-metadata-tags] [--audio-format [AUDIO-FORMAT]] [--audio-extension [AUDIO-EXTENSION]] [--audio-channels [AUDIO-CHANNELS]] [--audio-bitrate [AUDIO-BITRATE]] [--audio-samplerate [AUDIO-SAMPLERATE]] [--audio-codec [AUDIO-CODEC]] [--audio-quality [AUDIO-QUALITY]] [--audio-profile [AUDIO-PROFILE]] [--adjust-for-ipod] [--use-nero-chapter-format] [--fix-mime-type] [--no-conversion] [--trim-silence] [--add-silence [ADD-SILENCE]] [-o|--output-dir [OUTPUT-DIR]] [-p|--filename-template [FILENAME-TEMPLATE]] [--use-existing-chapters-file] [--reindex-chapters] [--fixed-length [FIXED-LENGTH]] [--chapters-filename [CHAPTERS-FILENAME]] [--by-silence] [--] <input>

What should I do now?

sandreas commented 2 years ago

Ok, now you are on the right track... the problem is, that docker cannot access your files because you are using ABSOLUTE PATHS...

M: seems to be a network share... that will not work you have to copy your files locally. Lets say, that

You could use:

cd C:\Users\MituButChi\

# the path must be provided relatively with slashes (NOT C:\Users\MituButChi\audiobooks_input\ but only audiobooks_input/) 
docker run -it --rm -v "$PWD":/mnt sandreas/m4b-tool:latest merge -v --jobs=2 --output-file="audiobooks/" --max-chapter-length=300,900 --adjust-for-ipod --batch-pattern="audiobooks_input/%g/%a/%s/%p - %n/"  --batch-pattern="audiobooks_input/%g/%a/%n/" "audiobooks_input/"

To split a file, the same rules apply:

# assuming the file to split is C:\Users\MituButChi\audiobooks_to_split\my-audio-book.m4b

cd C:\Users\MituButChi\
docker run -it --rm -v "$PWD":/mnt sandreas/m4b-tool:latest split --audio-format mp3 --audio-bitrate 96k --audio-channels 1 --audio-samplerate 22050 "audiobooks_to_split/my-audio-book.m4b"

Good luck :-)

MituButChi commented 2 years ago

Thank you for your quick reply.

I was about to edit my comment because after some playing around I understood it a bit more.

Could you please tell me how to set the alias? It has to do with the command prompt and not docker right? If it's too complicated to explain then it's all good, I'd just use the long commands instead.


M: seems to be a network share... that will not work you have to copy your files locally.

No actually I changed my local disk to M: because that's my initial haha. Sorry for the confusion.


So I tried to use the merge and split command now and here's what it says:

docker: Error response from daemon: create $PWD: "$PWD" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.

Now what do I do?

sandreas commented 2 years ago

You can replace $PWD by the directory, you are trying to work with:

# split audio book C:\Users\MituButChi\audiobooks_to_split\my-audio-book.m4b
docker run -it --rm -v "C:\Users\MituButChi\":/mnt sandreas/m4b-tool:latest split --audio-format mp3 --audio-bitrate 96k --audio-channels 1 --audio-samplerate 22050 "audiobooks_to_split/my-audio-book.m4b"

Note that on windows docker shares are very different because of permissions. Maybe you have to add C: or in your case M: to the local mounts / permissions.

I would go for a simplification first and try to put one sample audiobook to C:/Users/<your-username>/ and then try it there with the command above. As soon as it works, you can try to move your directories around and go for M: or something.

MituButChi commented 2 years ago

Close this to open another issue dedicated to split command.