-
-
Save nimatrueway/6ec71bb514e94c3ecbff4e2103b9bb76 to your computer and use it in GitHub Desktop.
Split an m4b into its chapters. No recoding is done, just splitting
This file contains 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 | |
# Description: Split an m4b into its chapters. No recoding is done, just splitting | |
# Usage: m4b_split.sh $input_file $output_dir/ | |
# Requires: ffmpeg, jq | |
# Author: Hasan Arous, Nima Taheri | |
# License: MIT | |
in="$1" | |
out="$2" | |
splits="" | |
ffprobe -i "$in" -print_format json -show_chapters > chapters.json | |
printf "\n\n\n\n" | |
jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | gsub("[/\\|?*<>:\" ]+"; "_"))' chapters.json | |
printf "\n\nEdit chapters \"$(pwd)/chapters.json\" if you like before proceeding.. [press Enter to continue]\n\n\n\n" | |
read | |
while read start end title; do | |
splits="$splits -c copy -map_chapters -1 -ss $start -to $end $out/$title.m4b" | |
done <<<$(cat chapters.json \ | |
| jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | gsub("[/\\|?*<>:\" ]+"; "_"))') | |
ffmpeg -i "$in" $splits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment