-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg-cut-merge
33 lines (28 loc) · 987 Bytes
/
ffmpeg-cut-merge
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env sh
TMP_DIR=/tmp/ffmpeg_cut_merge
PARTS_FILE=/tmp/ffmpeg_cut_merge/parts
timestamps=$1
video=$2
# check if files exist; if not exit
[ ! -e $timestamps ] || [ "$timestamps" = "" ] &&\
echo "ERROR: Timestamps file not found" && exit 1
[ ! -e $video ] || [ "$video" = "" ] &&\
echo "ERROR: Video file not found" && exit 1
[ "$(file $timestamps | awk '{print $2}')" != "ASCII" ] &&\
echo "Timestamps file not valid" && exit 1
mkdir $TMP_DIR
i=0
for line in $(cat $timestamps); do
start_timestamp=$(echo $line | cut -d '-' -f 1)
stop_timestamp=$(echo $line | cut -d '-' -f 2)
part="$TMP_DIR/part-$i.mkv"
ffmpeg -loglevel quiet -ss $start_timestamp -to $stop_timestamp\
-i $video -c copy $part
[ $? != 0 ] && echo "ERROR: could not cut video file" && break
echo "file '$part'" >> $PARTS_FILE
i=$(echo "$i+1" | bc)
done
ffmpeg -loglevel quiet -f concat -safe 0\
-i $PARTS_FILE -c copy $(date +"%Y-%m-%d_%H_%M_%S").mkv
rm -rf $TMP_DIR
rm $timestamps