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

Clément Bœsch ubitux at gmail.com
Sat Mar 23 20:08:55 CET 2013


On Sat, Mar 23, 2013 at 11:20:38AM +0100, Nicolas George wrote:
[...]
> > +for i in `$analysis_cmd
> 
> I believe $(...) should be preferred over `...`: more readable and more
> robust with regard to quoting.
> 
> >                          "amovie=$in,ebur128=metadata=1"`; do
> 
> Missing escaping of "$in".
> 

Fixed both.

> > +    [ "$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`
> 
> adjust=$((ref-loudness))
> 
> is standard, I believe.
> 

With integers yes, not with floats.

> > +if [ "$adjust" = "0" ]; then
> 
> Why sometimes [ $got_data -eq 0 ] and sometimes this version?
> 

got_data=0 means no analysis was run (because of an error in ffprobe, for
instance), while adjust=0 means the analysis was done but the file is
already normalized.

That got_data error handling was very clumsy, I changed it in the new
attached patch.

[...]

The new version also adds encoding option to make the usage of the script
a little more friendly.

-- 
Clément B.
-------------- next part --------------
From 333306306699523925518cd1b857db4c33408f42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Mon, 18 Mar 2013 04:02:51 +0100
Subject: [PATCH] tools: add audio normalize script example.

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

diff --git a/tools/normalize.sh b/tools/normalize.sh
new file mode 100755
index 0000000..fa33866
--- /dev/null
+++ b/tools/normalize.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+#FFPATH=./
+
+if [ $# -eq 2 ]; then
+    in=$1
+    ffopt=""
+    out=$2
+elif [ $# -eq 3 ]; then
+    in=$1
+    ffopt=$2
+    out=$3
+else
+    echo "usage: $0 <input> [encode_opt] <output>"
+    exit 1
+fi
+
+ref=-23
+loudness=$ref
+analysis_cmd="${FFPATH}ffprobe -v error -of compact=p=0:nk=1 -show_entries frame=metadata:tags=lavfi.r128.I -f lavfi"
+ebumeta=$($analysis_cmd "amovie='$in',ebur128=metadata=1")
+[ $? -ne 0 ] && exit 1
+for i in $(echo "$ebumeta" | xargs); do
+    [ "$i" != "" ] && loudness=$i
+done
+adjust=$(echo "$ref-($loudness)"|bc)
+if [ "$adjust" = "0" ]; then
+    echo "No normalization needed for $in"
+else
+    echo "Adjust $in by ${adjust}dB"
+    set -x
+    ${FFPATH}ffmpeg -i "$in" -af volume=${adjust}dB $ffopt "$out"
+fi
-- 
1.8.2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130323/ed1a2ba5/attachment.asc>


More information about the ffmpeg-devel mailing list