Created
January 8, 2024 00:22
-
-
Save oleasteo/18224566cab496d7ec91732be7ab6b00 to your computer and use it in GitHub Desktop.
Split m4b files by chapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ### | |
| # Splits an m4b file by chapter with the `mkvmerge` tool. Then, the parts | |
| # are converted back into m4b containers with `ffmpeg`. | |
| # | |
| # Usage: m4b-split-chapters [FILE] | |
| ### | |
| FILE="$1" | |
| [ -f "$FILE" ] || (echo 'Specify input file.'; exit 1) | |
| DIR="$(dirname "$(realpath "$FILE")")" | |
| tmpdir="$(mktemp -d)" | |
| mkvmerge -o "$tmpdir/$(basename "$FILE" .m4b).mka" --split chapters:all "$FILE" | |
| for f in "$tmpdir/"*.mka; do | |
| ffmpeg -i "$f" -c:a copy -vn -f mp4 "$tmpdir/$(basename "$f" .mka).m4b" | |
| done | |
| mv "$tmpdir/"*.m4b "$DIR" | |
| rm -rf "$tmpdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment