/
videoca.sh
executable file
·46 lines (33 loc) · 1002 Bytes
/
videoca.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
video_file=$1
timestamps_file=$2
tmp_dir="$HOME/Desktop/tmp"
filelist="$tmp_dir/filelist.txt"
mkdir "$tmp_dir"
echo "Video cutting and assembling: $video_file"
echo "Timestamps file: $timestamps_file"
counter=0
echo "" > "$filelist"
commands=()
while read -r line
do
# Make array from the line (space-separated timestamps)
timestamps=($line)
clip_start=${timestamps[0]}
clip_end=${timestamps[1]}
# Cut video section with slower seek & no copying of codecs
cmd="ffmpeg -y -i $video_file -ss $clip_start -to $clip_end $tmp_dir/$counter.mp4"
commands+=("$cmd")
echo "file '$counter.mp4'" >> "$filelist"
((counter++))
done < "$timestamps_file"
# Execute each command for cutting video sections
for cmd in "${commands[@]}"
do
echo "$cmd"
eval "$cmd"
done
# Merge clips into one file if more than one clip is available
if [ ${#commands[@]} -gt 1 ]; then
ffmpeg -y -f concat -safe 0 -i "$filelist" -c copy "$tmp_dir/merged.mp4"
fi