[FFmpeg-devel] [PATCH] tools: add audio normalize script example.
Stefano Sabatini
stefasab at gmail.com
Sun Mar 24 00:40:40 CET 2013
On date Saturday 2013-03-23 20:08:55 +0100, Clément Bœsch encoded:
> On Sat, Mar 23, 2013 at 11:20:38AM +0100, Nicolas George wrote:
[...]
> 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")
Note: this is broken in case $in contains filtergraph special chars
("," or ":"), using tools/ffescape to fix it may be a possibility.
> +[ $? -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
The script would be nicer if written in Perl/Python/Equivalent, but
don't consider this like a blocker.
--
FFmpeg = Fast and Free Miracolous Puritan Elastic Gem
More information about the ffmpeg-devel
mailing list