Skip to content

Instantly share code, notes, and snippets.

@0xquad
Last active March 24, 2017 03:40
Show Gist options
  • Save 0xquad/145e7c99385e36b04329ffebfc03ecff to your computer and use it in GitHub Desktop.
Save 0xquad/145e7c99385e36b04329ffebfc03ecff to your computer and use it in GitHub Desktop.
#!/bin/sh
# Splits an AV file with multiple chapters into separate files.
# Copyright (c) 2017, Alexandre Hamelin <alexandre.hamelin gmail.com>
[[ $# -gt 0 ]] || exit 1
file=$1
[[ -f "$file" ]] || exit 2
ext=${file##*.}
sub=" *Chapter #([0-9]+.[0-9]+): start ([0-9]+\.[0-9]+), end ([0-9]+\.[0-9]+)"
repl="-i \"$file\" -c:v copy -c:a copy -ss \2 -to \3 \"${file%.*}-\1.$ext\""
ffmpeg -i "$file" 2>&1 |
sed -r "/Chapter/ {s|$sub|$repl|;p}; d" | head -n 4 |
xargs -n 11 ffmpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment