From: Steven Baltakatei Sandoval Date: Sat, 20 Jan 2024 18:43:36 +0000 (+0000) Subject: feat(user/split_audiobook.sh):Split audiobooks by chapter X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/656dfa5d1aea91d2177050afa8eaaebba3349173?ds=inline;hp=4402ce96643b39688f2c4f5a9fc22b7cc2ff9b52 feat(user/split_audiobook.sh):Split audiobooks by chapter --- diff --git a/user/split_audiobook.sh b/user/split_audiobook.sh new file mode 100644 index 0000000..8838efe --- /dev/null +++ b/user/split_audiobook.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Desc: Split an audio file by chapter +# Depends: ffmpeg, jq +# Ref/Attrib: [1] Hasan Arous. MIT license. https://unix.stackexchange.com/a/612124 +# [2] John Smith. https://unix.stackexchange.com/a/712600 + +in="$1"; +out="$2"; +splits=""; +n=0; +while read start end title; do + newTitle="$(echo "$title" | sed "s/ /_/g")"; + newTitle="$(printf "%02d..%s" "$n" "$newTitle")"; + splits="$splits -c copy -ss $start -to $end $out/$newTitle.m4b"; + ((n++)); +done <<< $(ffprobe -i "$in" -print_format json -show_chapters \ + | jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | sub(" "; "_"))'); +ffmpeg -i "$in" $splits; + +# Author: Steven Baltakatei Sandoval +# License: GPLv3+