#!/bin/bash if [ $# -ne 2 ] then echo "Usage:" echo "$0 VIDEO-FILE TIMES-FILE" echo "" echo "Video file will be split into parts at times specified in times-file" echo "" echo "Times file contains times in seconds each on separate line" echo "" echo "Empty lines (except for trailing) will confuse this script" echo "" echo "Written by Jakub SkoĊepa (jakub at skorepa.info) in 2015-4" echo "Distributed under:" echo "GNU General Public License 3 or newer as published by Free Software Foundation" exit fi file=$1 lengths=$2 ffmpeg -i $file -to $(sed "1q;d" $lengths) 1.mp4 N=$(cat $lengths | wc -l) Nm=$[N-1] for I in $(eval echo "{1..$Nm}") do t=$(sed $I"q;d" $lengths) #start time t2=$(sed $[I+1]"q;d" $lengths) #end time t0=$[t-10] # start time - 10 t1=$[t2-t0] # length of segment + 10 ffmpeg -ss $t0 -i $file -ss 10 -to $t1 $I".mp4" done t=$(sed $N"q;d" $lengths) ffmpeg -ss $[t-10] -i $file -ss 10 $N".mp4"