-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcc_norm.sh
More file actions
executable file
·57 lines (48 loc) · 1.57 KB
/
cc_norm.sh
File metadata and controls
executable file
·57 lines (48 loc) · 1.57 KB
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
#!/bin/bash
# Helper script to normalize video/audio file.
# Output ffmpeg -a options.
inFile=$1
ffmpeg_bin=${2:-'/usr/bin/ffmpeg'}
sample=${3:-'-ss 01:00 -t 06:00'}
target_i="-24.0"
target_tp="-2.0"
target_lra="11.0"
outFile="/tmp/sample.json"
ff_string="${ffmpeg_bin} -hide_banner -y"
ff_string+=" ${sample}"
ff_string+=" -i \"${inFile}\""
ff_string+=" -vn -sn"
ff_string+=" -filter:a loudnorm="
ff_string+="I=${target_i}:"
ff_string+="tp=${target_tp}:"
ff_string+="LRA=${target_lra}:"
ff_string+="print_format=json"
ff_string+=" -f mp4 /dev/null"
bash -c "$ff_string" 2>&1 | sed -n '/{/,/}/p' > "$outFile"
STATUS=$?
if (( STATUS > 0 )); then
exit $STATUS
fi
measured_i=$(jq -r .input_i < "$outFile")
measured_tp=$(jq -r .input_tp < "$outFile")
measured_lra=$(jq -r .input_lra < "$outFile")
measured_thresh=$(jq -r .input_thresh < "$outFile")
measured_offset=$(jq -r .target_offset < "$outFile")
if [[ -z "$measured_i" || -z "$measured_tp" || -z "$measured_lra" || -z "$measured_thresh" || -z "$measured_offset" ]]; then
echo "ERROR: Could not parse loudnorm output."
exit 1
fi
loudnorm_string+="-filter:a loudnorm="
loudnorm_string+="print_format=summary:"
loudnorm_string+="linear=true:"
loudnorm_string+="I=${target_i}:"
loudnorm_string+="tp=${target_tp}:"
loudnorm_string+="LRA=${target_lra}:"
loudnorm_string+="measured_I=${measured_i}:"
loudnorm_string+="measured_tp=${measured_tp}:"
loudnorm_string+="measured_LRA=${measured_lra}:"
loudnorm_string+="measured_thresh=${measured_thresh}:"
loudnorm_string+="offset=${measured_offset}"
echo "$loudnorm_string"
rm "$outFile"
exit $STATUS