[FFmpeg-devel] [PATCH] tools: add audio normalize script example.

Clément Bœsch ubitux at gmail.com
Mon Mar 18 04:02:51 CET 2013


---
 tools/normalize.sh | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 tools/normalize.sh

diff --git a/tools/normalize.sh b/tools/normalize.sh
new file mode 100755
index 0000000..6eb07f6
--- /dev/null
+++ b/tools/normalize.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+analysis_cmd="ffprobe -v 0 -show_frames -of compact=p=0:nk=1 -show_entries frame=metadata:tags=lavfi.r128.I -f lavfi"
+
+norm_cmd() {
+    # Set your smart encode settings here
+    ffmpeg -i "$1" -af volume=${2}dB "$3"
+}
+
+if [ $# -ne 2 ]; then
+    echo "usage: $0 <input> <output>"
+    exit 1
+fi
+
+in=$1
+out=$2
+
+ref=-23
+loudness=$ref
+got_data=0
+for i in `$analysis_cmd "amovie=$in,ebur128=metadata=1"`; do
+    [ "$i" != "" ] && loudness=$i
+    got_data=1
+done
+if [ $got_data -eq 0 ]; then
+    echo "Something got wrong"
+    exit 1
+fi
+adjust=`echo "$ref-($loudness)"|bc`
+if [ "$adjust" = "0" ]; then
+    echo "No normalization needed for $0"
+    exit 0
+fi
+echo "Adjust $in by ${adjust}dB"
+norm_cmd "$in" "$adjust" "$out"
-- 
1.8.2



More information about the ffmpeg-devel mailing list