-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcv
executable file
·58 lines (43 loc) · 1.46 KB
/
cv
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
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
if ! command -v ffmpeg &>/dev/null; then
echo -e "\033[31mffmpeg could not be found\033[0m"
exit
fi
if [ $# -lt 2 ]; then
echo "Usage: cv time_range1,time_range2,... input_file [out_dir]"
exit
fi
IFS=',' read -ra time_ranges <<<"$1"
input_file=$2
if [ ! -f "$input_file" ]; then
echo "Input file does not exist"
exit
fi
if [ $# -eq 3 ]; then
out_dir="$3"
else
out_dir=$(dirname -- "$input_file")
fi
input_file_name=$(basename -- "$input_file")
input_file_extension="${input_file_name##*.}"
input_file_name="${input_file_name%.*}"
source /usr/local/bin/convert_time_format
for time_range in "${time_ranges[@]}"; do
formatted_time=$(convert_time_format "${time_range}")
echo $formatted_time
# 将时间范围的开始和结束时间转换为所需的格式
start_time=${formatted_time%-*}
end_time=${formatted_time#*-}
output_file_name="$input_file_name"__"${start_time//:/_}"-"${end_time//:/_}"."$input_file_extension"
output_file="$out_dir/$output_file_name"
echo "Processing $start_time to $end_time..."
# -avoid_negative_ts 1
# 使用转换后的时间格式进行剪切
ffmpeg -loglevel error -ss "$start_time" -to "$end_time" -accurate_seek -i "$input_file" -c copy "$output_file"
if [ $? -eq 0 ]; then
echo -e "\033[32mOutput file saved as $output_file\033[0m"
else
echo -e "\033[31mFailed!\033[0m"
fi
done
echo -e "\033[32mAll tasks have been completed\033[0m"