-
Notifications
You must be signed in to change notification settings - Fork 0
/
zmix_split.sh
executable file
·170 lines (149 loc) · 4.71 KB
/
zmix_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
#############################################
#
# Generate Random Sequences from same track
#
#############################################
# requirements
# sudo apt install rubberband-cli
# sudo apt install ffmpeg
#shopt -s nullglob dotglob
while getopts i:h:d:t:s: option; do
# shellcheck disable=SC2220
case "${option}" in
i) FILE=${OPTARG} ;;
h) HELP=${OPTARG} ;;
d) DEL=${OPTARG} ;;
t) TYPE=${OPTARG} ;;
s) SIZE=${OPTARG} ;;
esac
done
if [ "$HELP" ]; then
echo "--------------------------------------------------"
echo "HELP: "
echo "usage: bash zmix_split.sh -i load/in.mp3 -dy -t * -s 0.6"
echo ""
echo "options:"
echo "-h yes - help"
echo "-i file.mp3 - specify input file"
echo "-d yes - delete old generated temp files"
echo "-t * - chose setup for split:"
echo " * = default "
echo " 1 = volume=3dB"
echo " 2 = volume=3dB, equalizer=f=440:width_type=o:width=2:g=-5,areverse"
echo " 3 = volume=3dB,equalizer=f=40:width_type=o:width=2:g=-7,areverse"
echo " 4 = volume=3dB,equalizer=f=540:width_type=o:width=2:g=-9,areverse"
echo "--------------------------------------------------"
exit
fi
echo "------------------start---------------------------"
if [ -z "$SIZE" ]
then
echo "\$SIZE is empty"
SIZE=1
#exit
else
echo "\$SIZE is NOT empty"
fi
echo "size specified is: " $SIZE
echo "Loaded File: " "$FILE"
if [ ! -f "$FILE" ]; then
echo "File does not exist! Bye!"
exit
fi
# check if arg d is set
if [ "$DEL" ]; then
DEL="yes"
echo "\DEL set to $DEL."
fi
echo "Delete existing files? " $DEL
# exit;
#--------------------------------------------
# REMOVE OLD SPLIT FILES
#--------------------------------------------
if [ "$DEL" ]; then
files=(/split/*)
if [ ${#files[@]} -gt 0 ]; then
for f in split/*.wav; do
rm -f "$f"
#echo "Removed file: $f"
done
fi
files=(/output/*)
if [ ${#files[@]} -gt 0 ]; then
for f in output/*.wav; do
rm -f "$f"
#echo "Removed file: $f"
done
fi
fi
sleep 2s
#--------------------------------------------
# SPLIT WAV N FILES 1 SECOND LENGTH
#--------------------------------------------
case $TYPE in
1)
echo "SETUP 1 > volume=3dB"
ffmpeg -i "$FILE" -map 0 -f segment -segment_time "$SIZE" \
-af "volume=3dB" -t 20 -y split/split_%03d.wav 2>/dev/null
;;
2)
echo "SETUP 2 > volume=3dB, equalizer=f=440:width_type=o:width=2:g=-5,areverse"
ffmpeg -i "$FILE" -map 0 -f segment -segment_time "$SIZE" \
-af "volume=3dB, equalizer=f=440:width_type=o:width=2:g=-5,areverse" -t 20 -y split/split_%03d.wav 2>/dev/null
;;
3)
echo "SETUP 3 > volume=3dB,equalizer=f=40:width_type=o:width=2:g=-7,areverse"
ffmpeg -i "$FILE" -map 0 -f segment -segment_time "$SIZE" \
-af "volume=3dB,equalizer=f=40:width_type=o:width=2:g=-7,areverse" -t 20 -y split/split_%03d.wav 2>/dev/null
;;
4)
echo "SETUP 4 > volume=3dB,equalizer=f=540:width_type=o:width=2:g=-9,areverse"
ffmpeg -i "$FILE" -map 0 -f segment -segment_time "$SIZE" -segment_time_delta 0.9 \
-af "volume=3dB,equalizer=f=540:width_type=o:width=2:g=-9,areverse" -t 20 -y split/split_%03d.wav 2>/dev/null
;;
*)
echo "SETUP default"
ffmpeg -i "$FILE" -map 0 -f segment -segment_time "$SIZE" -c copy -y split/split_%03d.wav 2>/dev/null
;;
esac
sleep 2s
# shellcheck disable=SC2012
FILESMAX=$(ls split/ | wc -l)
MAXFILES=$(("$FILESMAX"-1))
echo "$MAXFILES"
# shellcheck disable=SC2034
for i in {1..16}; do
#--------------------------------------------
#CONCAT 4 WAVS - Rand(10+x)
#--------------------------------------------
# generate random number from 0 to N
# shellcheck disable=SC2046
RANDOM1=$(printf %03d $(shuf -i0-$MAXFILES -n1))
# shellcheck disable=SC2046
RANDOM2=$(printf %03d $(shuf -i0-$MAXFILES -n1))
# shellcheck disable=SC2046
RANDOM3=$(printf %03d $(shuf -i0-$MAXFILES -n1))
# shellcheck disable=SC2046
RANDOM4=$(printf %03d $(shuf -i0-$MAXFILES -n1))
# shellcheck disable=SC2046
RANDOM5=$(printf %03d $(shuf -i0-$MAXFILES -n1))
# shellcheck disable=SC2046
RANDOM6=$(printf %03d $(shuf -i0-$MAXFILES -n1))
# echo "$(date +%s)"
# shellcheck disable=SC2086
echo "Random Sequences: " $RANDOM1, $RANDOM2, $RANDOM3, $RANDOM4, $RANDOM5, $RANDOM6
cmd="ffmpeg
-i split/split_$RANDOM1.wav
-i split/split_$RANDOM2.wav
-i split/split_$RANDOM3.wav
-i split/split_$RANDOM4.wav
-i split/split_$RANDOM5.wav
-i split/split_$RANDOM6.wav
-filter_complex [0:0][1:0][2:0][3:0][4:0][5:0]concat=n=6:v=0:a=1[out]
-map '[out]' output/zmix_$(date +%s).wav 2>/dev/null " # -report
# shellcheck disable=SC2086
eval $cmd
sleep 2s
done
echo "------------------finish---------------------------"