Skip to content

Instantly share code, notes, and snippets.

@jkoop
Last active September 30, 2022 01:37
Show Gist options
  • Save jkoop/a70020ba6e450cfd579c1efc58ba15a0 to your computer and use it in GitHub Desktop.
Save jkoop/a70020ba6e450cfd579c1efc58ba15a0 to your computer and use it in GitHub Desktop.
use ffmpeg to split file by chapter metadata
#!/bin/bash
while [ $# -gt 0 ]; do
extension="${1##*.}"
ffmpeg -i "$1" 2> tmp.txt
# Chapter #0:0: start 0.000000, end 1290.013333
# first _ _ start _ end
while read -r first _ _ start _ end; do
if [[ $first = Chapter ]]; then
read # discard line with Metadata:
read _ _ chapter
ffmpeg -vsync 2 -i "$1" -ss "${start%?}" -to "$end" -c copy "$chapter."$extension < /dev/null
fi
done < tmp.txt
rm tmp.txt
shift # https://unix.stackexchange.com/a/174568
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment