Skip to content

Instantly share code, notes, and snippets.

@antonalekseev
Created January 11, 2021 00:34
Show Gist options
  • Select an option

  • Save antonalekseev/d4f7ae1d360c6a4573a55adeb38caf0c to your computer and use it in GitHub Desktop.

Select an option

Save antonalekseev/d4f7ae1d360c6a4573a55adeb38caf0c to your computer and use it in GitHub Desktop.
Split audiobook into files containing individual chapters
#!/bin/bash
# Description: Modified version of script from https://unix.stackexchange.com/a/612124
# Requires: ffmpeg, jq
# Author: Hasan Arous
# License: MIT
in="$1"
out="$2"
splits=""
while read start end title; do
splits="$splits -c copy -ss $start -to $end ${out}_$title.m4a"
done <<<$(ffprobe -i "$in" -print_format json -show_chapters \
| jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | sub(" "; "_"))')
ffmpeg -i "$in" $splits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment