-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg-audio-split.sh
59 lines (50 loc) · 1.41 KB
/
ffmpeg-audio-split.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
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
check_ffmpeg() {
if ! command -v ffmpeg &> /dev/null
then
echo "ffmpeg could not be found."
echo "To install ffmpeg, follow these instructions:"
echo "For Debian/Ubuntu: sudo apt update && sudo apt install ffmpeg"
echo "For Fedora: sudo dnf install ffmpeg"
echo "For macOS with Homebrew: brew install ffmpeg"
echo "Please install ffmpeg and run this script again."
exit 1
fi
}
check_ffmpeg
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <audio_file> <subdivisions_file>"
exit 1
fi
source="$1"
subdivisions_file="$2"
if [ ! -e "$subdivisions_file" ]; then
echo "The subdivisions file '$subdivisions_file' does not exist."
exit 1
fi
start_times=()
end_times=()
titles=()
while IFS= read -r line
do
if [ -z "$line" ]; then
continue
fi
t0=$(echo "$line" | awk '{print $1}')
t1=$(echo "$line" | awk '{print $2}')
title=$(echo "$line" | cut -d ' ' -f 3-)
start_times+=("$t0")
end_times+=("$t1")
titles+=("$title")
done < "$subdivisions_file"
for ((i = 0; i < ${#start_times[@]}; i++)); do
title=${titles[i]}
t0=${start_times[i]}
t1=${end_times[i]}
echo "-----------------------------------------"
echo "Title: $title"
echo "Start: $t0"
echo "End: $t1"
echo "-----------------------------------------"
ffmpeg -i "$source" -acodec copy -ss "$t0" -to "$t1" "$title"
done