#!/usr/bin/env bash set -efu input="$1"; shift ffprobe -print_format csv -show_chapters "$input" | cut -d ',' -f '5,7,8' | while IFS=, read -r start end chapter; do ffmpeg \ -nostdin \ -ss "$start" -to "$end" \ -i "$input" \ -c copy \ -map 0 \ -map_chapters -1 \ "$@" \ "$(printf %s "${input%.*}.$chapter.${input##*.}" | tr / _ | sed -e "s/\.\./_/g")" done