feat(unitproc/bkt-replace_contractions):Use backreferences
[BK-2020-03.git] / user / split_audiobook.sh
1 #!/bin/bash
2 # Desc: Split an audio file by chapter
3 # Depends: ffmpeg, jq
4 # Version: 0.0.1
5 # Ref/Attrib: [1] Hasan Arous. MIT license. https://unix.stackexchange.com/a/612124
6 # [2] John Smith. https://unix.stackexchange.com/a/712600
7
8 in="$1";
9 out="$2";
10 splits="";
11 n=0;
12 while read start end title; do
13 newTitle="$(echo "$title" | sed "s/ /_/g")";
14 newTitle="$(printf "%02d..%s" "$n" "$newTitle")";
15 splits="$splits -c copy -ss $start -to $end $out/$newTitle.m4b";
16 ((n++));
17 done <<< $(ffprobe -i "$in" -print_format json -show_chapters \
18 | jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | sub(" "; "_"))');
19 ffmpeg -i "$in" $splits;
20
21 # Author: Steven Baltakatei Sandoval
22 # License: GPLv3+