-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlslimiterconvert.sh
executable file
·88 lines (76 loc) · 2.77 KB
/
hlslimiterconvert.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
#!/bin/bash
SAVEIFS="${IFS}"
IFS=$(echo -en "\n\b")
if [ -d "$1" ]; then
echo "$1:"
FILES=$(find -E "$1" -maxdepth 1 -type f -regex '.*(.wav|m4a)$')
else
FILES="$(ls "$@" | awk '/.wav|.m4a$/ { print $0 }')"
fi
echo "converting: " ${1} "..."
SAVEIFS="${IFS}"
IFS=$(echo -en "\n\b")
for FILE in $FILES; do
base="$(basename "$FILE")"
dir="$(dirname "$FILE")"
extension="${base:(-4)}"
output_folder="${dir}/${base%${extension}}-HLS"
if [ ! -d "${output_folder}" ]; then
mkdir "${output_folder}"
fi
temp_file="$(mktemp)"
ffmpeg \
-i "$FILE" \
-hide_banner \
-af loudnorm=I=-16:TP=-3.0:dual_mono=true:print_format=summary \
-f null - \
2> "$temp_file"
integrated="$(awk '/Input Integrated:/ { print $3 }' "$temp_file")"
lra="$(awk '/Input LRA:/ { print $3 }' "$temp_file")"
truepeak="$(awk '/Input True Peak:/ { print $4 }' "$temp_file")"
thresh="$(awk '/Input Threshold:/ { print $3 }' "$temp_file")"
if [ ${truepeak:0:1} == "+" ]; then
truepeak=${truepeak##+}
fi
plr=$(bc -l <<< "${truepeak}-(${integrated})")
# ffmpeg \
# -hide_banner \
# -loglevel fatal \
# -i "$FILE" \
# -af alimiter=level=false:level_in=${level}dB:limit=-3.0dB \
# or
# -af volume=${level}dB \
# -ar 44100 \
# -c:a aac \
# -movflags +faststart \
# -map 0:a \
# -map 0:a \
# -map 0:a \
# -b:a:0 128000 \
# -b:a:1 96000 \
# -b:a:2 64000 \
# -var_stream_map "a:0 a:1 a:2" \
# -master_pl_name main.m3u8 \
# -f HLS \
# -start_number 0 \
# -hls_time 10 \
# -hls_list_size 0 \
# -hls_segment_filename "${output_folder}/v%v/seq%d.ts" \
# "${output_folder}/v%v/br.m3u8"
COMMAND="ffmpeg -hide_banner -loglevel fatal -i \"$FILE\" "
if [ $(echo "$integrated > -15.2" | bc -l) -eq 1 ] || [ $(echo "$integrated < -16.8" | bc -l) -eq 1 ] || [ $(echo "$truepeak > -2.6" | bc -l) -eq 1 ]; then
echo "normalizing ${base}"
level=$(bc -l <<< "-16.0-(${integrated})")
if [ $(echo "$plr > 13.0" | bc -l) -eq 1 ]; then
COMMAND+="-af \"alimiter=level=false:level_in=${level}dB:limit=-3.0dB\" "
else
COMMAND+="-af \"volume=${level}dB\" "
fi
else
echo "${base} is within tolerance"
fi
COMMAND+="-ar 44100 -c:a aac -movflags +faststart -map 0:a -map 0:a -map 0:a -b:a:0 128000 -b:a:1 96000 -b:a:2 64000 -var_stream_map \"a:0 a:1 a:2\" -master_pl_name main.m3u8 -f HLS -start_number 0 -hls_time 10 -hls_list_size 0 -hls_segment_filename \"${output_folder}/v%v/seq%d.ts\" \"${output_folder}/v%v/br.m3u8\""
eval "$COMMAND"
rm "$temp_file"
done
echo "done"