From 5d5ba2c95dfa0311a4aebfe012af7842c4f7b7ef Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 4 Mar 2018 18:20:34 +0100 Subject: [PATCH] Added scripts for MP3 loudness normalisation based on EBU R123 instead of ReplayGain. (lossless using mp3gain to modify values) --- mp3loud_track.sh | 27 +++++++++++++++++++++++++++ mp3loud_tracks.sh | 14 ++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 mp3loud_track.sh create mode 100755 mp3loud_tracks.sh diff --git a/mp3loud_track.sh b/mp3loud_track.sh new file mode 100755 index 0000000..690b00d --- /dev/null +++ b/mp3loud_track.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Install mp3gain from: https://launchpad.net/~flexiondotorg/+archive/ubuntu/audio +# Install bs1770gain from package manager + +TARGET_LOUDNESS=-14 + +# Normalise MP3 to 89 dB, add tags to file +mp3gain -q -k -p -r -s i "$1" > /dev/null + +# Find actual EBU R128 loudness, show relative to $TARGET_LOUDNESS LUFS +LOUDADJUST=`bs1770gain --norm $TARGET_LOUDNESS --xml "$1" | grep -m 1 integrated | sed -e 's/^.*lu="\(.*\)".*$/\1/'` +echo "[$1] Deviation from $TARGET_LOUDNESS LUFS: $LOUDADJUST LU" + +# Calculate gain adjustment (in steps of 1.5 dB/~LU), round using printf +GAINADJUST=`echo "scale=4;$LOUDADJUST / 1.5" | bc` +GAINADJUST=`printf %0.f $GAINADJUST` + +# To ALWAYS stay BELOW -14 LUFS, use this: +#GAINADJUST=`echo "$LOUDADJUST / 1.5" | bc` + +if [ "$GAINADJUST" -ne 0 ]; then + echo "[$1] Adjust gain by: $GAINADJUST" + # Use this call to have clipping-prevention which doesn't work when modifying gain directly + mp3gain -q -k -p -r -s i -m $GAINADJUST "$1" +else + echo "[$1] No further adjustment necessary." +fi diff --git a/mp3loud_tracks.sh b/mp3loud_tracks.sh new file mode 100755 index 0000000..772377f --- /dev/null +++ b/mp3loud_tracks.sh @@ -0,0 +1,14 @@ +#!/bin/sh +if [ "$#" = "0" ]; then + echo "Usage: $0 file1 [file2 file3 ... fileN]" + exit 1 +fi + +if [ -z "$CONCURRENCY_LEVEL" ]; then + CONCURRENCY_LEVEL=1 +fi + +echo "Processing using $CONCURRENCY_LEVEL processes..." +nice -n2 find "$@" -print0 | xargs -0 -P $CONCURRENCY_LEVEL -n 1 -I {} /opt/mbirth/mp3loud_track.sh "{}" + +echo "All done."