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

Nicolas George nicolas.george at normalesup.org
Sat Mar 23 11:20:38 CET 2013


L'octidi 28 ventôse, an CCXXI, Clement Boesch a écrit :
> ---
>  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

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".

> +    [ "$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.

> +if [ "$adjust" = "0" ]; then

Why sometimes [ $got_data -eq 0 ] and sometimes this version?

> +    echo "No normalization needed for $0"
> +    exit 0
> +fi
> +echo "Adjust $in by ${adjust}dB"
> +norm_cmd "$in" "$adjust" "$out"

On the whole, I do not like very much the need of using amovie, but I see
no better solution right now. Extending one of ffmpeg's technical output
formats (ffmetadata or framecrc maybe) to dump per-frame metadata may be a
better long-term solution. But I do not consider this blocking.

In fact, it is still the same problem of getting script-friendly output from
filters: at some point we will need a clean solution.

Regards,

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


More information about the ffmpeg-devel mailing list