Skip to content

Instantly share code, notes, and snippets.

@aularon

aularon/m4b_split.sh

Last active Nov 2, 2020
Embed
What would you like to do?
Split an m4b into its chapters. No recoding is done, just splitting
#!/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
# License: MIT
in="$1"
out="$2"
splits=""
while read start end title; do
splits="$splits -c copy -ss $start -to $end $out/$title.m4b"
done <<<$(ffprobe -i "$in" -print_format json -show_chapters \
| jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | sub(" "; "_"))')
ffmpeg -i "$in" $splits
@mattura

This comment has been minimized.

Copy link

@mattura mattura commented Nov 2, 2020

Thanks for this!
My shell's 'read' doesn't split the chapter values as required, I had to add a delimiter:

while read '-d|' start end title; do
splits="$splits -c copy -ss $start -to $end $out/$title.m4b"
done <<<$(ffprobe -i "$in" -print_format json -show_chapters \
| jq -r '.chapters[] | .start_time + " " + .end_time + " " + (.tags.title | sub(" "; "_")) + "|"')`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.