-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcut-video-segment
More file actions
executable file
·26 lines (21 loc) · 878 Bytes
/
cut-video-segment
File metadata and controls
executable file
·26 lines (21 loc) · 878 Bytes
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
#!/usr/bin/env bash
inputFile="$1"
printf "Start time: "
read -r fromTime
printf "End time: "
read -r toTime
filename="$(basename -- "$inputFile")"
extension="${filename##*.}"
filename="${filename%.*}"
dir_name="$(dirname "$inputFile")"
partNo="$(find "$dir_name/" -maxdepth 1 -name "$filename.*.mp4" | rev | cut -d '.' -f-2 | rev | cut -d '.' -f1 | sort -rn | head -n1)"
if [[ -z "$partNo" ]]; then
partNo="0"
fi
partNo="$((partNo + 1))"
tmpFilename="$filename.$partNo.tmp.$extension"
newFilename="$filename.$partNo.mp4"
ffmpeg -y -i "$inputFile" -async 20 -ss "$fromTime" -to "$toTime" "$tmpFilename"
cut_filter="$(ffmpeg -i "$tmpFilename" -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | sort | uniq -c | sort -nr | rev | cut -d' ' -f1 | rev | head -n1)"
ffmpeg -y -i "$tmpFilename" -vf "$cut_filter" -map_metadata -1 "$newFilename"
rm -f "$tmpFilename"