Skip to content

Instantly share code, notes, and snippets.

@martinbeentjes
Last active July 21, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbeentjes/e5da32091ac581a2f1ed39d656e5fda6 to your computer and use it in GitHub Desktop.
Save martinbeentjes/e5da32091ac581a2f1ed39d656e5fda6 to your computer and use it in GitHub Desktop.
Splitting mp4 files into clips
01.mp4 00:00:00 00:02:44
01.mp4 00:02:44 00:06:12
01.mp4 00:06:12 00:06:52
01.mp4 00:06:52 00:09:41
01.mp4 00:09:41 00:13:55
01.mp4 00:13:55 00:14:34
01.mp4 00:14:34 00:20:31
01.mp4 00:20:31 00:41:55
01.mp4 00:41:55 01:00:53
---
02.mp4 00:01:00 00:04:34
#!/bin/bash
IFS=$'\n'
set -f
cc=1
for i in $(cat < "$1"); do
if [ "$i" == "---" ]
then
cc=0
continue
fi
fn=$(echo $i | awk '{print $1}')
st=$(echo $i | awk '{print $2}')
et=$(echo $i | awk '{print $3}')
filename=$(basename -- "$fn")
extension="${filename##*.}"
filename="${filename%.*}"
cfn=$(printf "%s_%d.mp4" $filename $cc)
ffmpeg -i $fn -ss $st -to $et -c copy $cfn
cc=$((cc+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment