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.12k stars 78 forks source link

Running the same command gives inconsistent results - Windows WSL2 Ubuntu 20.04 #222

Open kanjieater opened 1 year ago

kanjieater commented 1 year ago

I'm not sure if this is an issue with WSL2 as mentioned in #204 or something else.

https://github.com/sandreas/m4b-tool/issues/204#issuecomment-1294001153

I can run the same command with the docker and get inconsistent results. I'm not sure what this error indicates image

Could not detect length for file 20-finished.m4b, output 'mp4info version 2.1.1
/tmp/m4b-tool/20-finished.m4b:
ReadChildAtoms: "/tmp/m4b-tool/20-finished.m4b": In atom  missing child atom moov
FindIntegerProperty: no such property - moov.mvhd.modificationTime (src/mp4file.cpp,831)
mp4info: can't open /tmp/m4b-tool/20-finished.m4b
' does not contain a valid length value

I'm simply running a merge command with jobs matching my core count. docker run -it --rm -u $(id -u):$(id -g) -v "$FOLDER":/mnt sandreas/m4b-tool:latest merge "./$(echo $NAME)_splitted/" --output-file="./$NAME.m4b" --jobs=$(nproc --all)

kanjieater commented 1 year ago

I also switched to hypervisor and am running from windows now. The same thing happens image

ERROR       41499ms Could not detect length for file 22-finished.m4b, output 'mp4info version 2.1.1
/tmp/m4b-tool/22-finished.m4b:
ReadChildAtoms: "/tmp/m4b-tool/22-finished.m4b": In atom  missing child atom moov
FindIntegerProperty: no such property - moov.mvhd.modificationTime (src/mp4file.cpp,831)
mp4info: can't open /tmp/m4b-tool/22-finished.m4b
' does not contain a valid length value
sandreas commented 1 year ago

Mmh strange. Looks like a windows issue, I recently came across the jellyfin docker instructions where it is recommended to use a bind mount instead of a volume to overcome filesystem issues, but I think this is not possible on windows?!

 docker run -it --rm -u $(id -u):$(id -g) \
--mount type=bind,source=$FOLDER,target=/mnt
  sandreas/m4b-tool:latest merge "./$(echo $NAME)_splitted/" --output-file="./$NAME.m4b" --jobs=$(nproc --all)

And could you verify the issue by using an older docker image?

docker pull sandreas/m4b-tool:2022-11-05
kanjieater commented 1 year ago

image

I can confirm it exists on older builds

The mount flag also works but doesn't seem to be related image

While my job count is accurate at 32 for a i9-13900ks, it seems like this issue happens more for a high job count. Lower job counts like 4 seem to work more consistently. I'm not sure if this is just luck though.

kanjieater commented 1 year ago

I'm still running into this. I've tried quite a few different methods as mentioned above, but at this point if I need to combine my mp4's into a m4b, how would I do that outside of m4b-tool?

""" Could not detect length for file 13-finished.m4b, output 'mp4info version 2.1.1 /tmp/m4b-tool/13-finished.m4b: ReadChildAtoms: "/tmp/m4b-tool/13-finished.m4b": In atom missing child atom moov FindIntegerProperty: no such property - moov.mvhd.modificationTime (src/mp4file.cpp,831) mp4info: can't open /tmp/m4b-tool/13-finished.m4b ' does not contain a valid length value """

sandreas commented 1 year ago

I'm still running into this. I've tried quite a few different methods as mentioned above, but at this point if I need to combine my mp4's into a m4b, how would I do that outside of m4b-tool?

Which docker image are you using? In newer images / recent versions of m4b-tool tone should be used for length detection - i think this is not the case here.

kanjieater commented 1 year ago

I'm still running into this. I've tried quite a few different methods as mentioned above, but at this point if I need to combine my mp4's into a m4b, how would I do that outside of m4b-tool?

Which docker image are you using? In newer images / recent versions of m4b-tool tone should be used for length detection - i think this is not the case here.

The latest docker image was from around 2 months ago it looks so, so I do have and am using version f0c29aaf4f4a .

I'm getting this error still:

Could not detect length for file 06-finished.m4b, output 'mp4info version 2.1.1
/tmp/m4b-tool/06-finished.m4b:
ReadChildAtoms: "/tmp/m4b-tool/06-finished.m4b": In atom  missing child atom moov
FindIntegerProperty: no such property - moov.mvhd.modificationTime (src/mp4file.cpp,831)
mp4info: can't open /tmp/m4b-tool/06-finished.m4b
' does not contain a valid length value
sandreas commented 1 year ago

I'm getting this error still:

Mhh, that is strange. Well, I'll investigate this again, may take a while. I already was going to provide another file iterator using system tools like find... this is a really annoying issue. sorry.

kanjieater commented 1 year ago

I'm getting this error still:

Mhh, that is strange. Well, I'll investigate this again, may take a while. I already was going to provide another file iterator using system tools like find... this is a really annoying issue. sorry.

No problem - I completely agree, it's core functionality that app developers should easily be able to access without you having to do a this much work on your side.

For working around the files not always being picked up I have been using this.

#!/bin/bash

audiobooks_path="/mnt/a/audiobooksm4b/"

# Loop over each audiobook folder
for audiobook_folder in "${audiobooks_path}"/*/
do
  # Print out the name of the audiobook folder
  echo "Merging files in ${audiobook_folder}..."

  # Get the audiobook name
  audiobook_name="$(basename "${audiobook_folder}")"

  # Get the list of mp4 files in the audiobook folder
  mp4_files=$(ls -1v "${audiobook_folder}"*.mp4)

  # Replace audiobooks_path with "./" in each mp4 file path
  mp4_files=$(echo "$mp4_files" | sed "s|${audiobook_folder}|./|g")

  # Wrap each mp4 file path in quotes
  mp4_files=$(echo "$mp4_files" | awk '{printf "\"%s\" ", $0}')

  # Run the m4b-tool Docker container to merge the MP4 files
  docker_cmd="docker run -it --rm -u $(id -u):$(id -g) -v \"${audiobook_folder}\":/mnt sandreas/m4b-tool:latest merge ${mp4_files} --output-file \"./${audiobook_name}.m4b\" --jobs $(nproc --all)"

  echo "$docker_cmd"
  eval "$docker_cmd"
done

Though, I still found I had to check the outputs of the chapters to make sure they matched, as sometimes m4b-tool would make the m4b skipping mp4 files but still creating the m4b. So i'm working around that with this:

https://github.com/kanjieater/AudiobookTextSync/blob/master/merge.py