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