I use the Loundnorm filter in Ffmpeg to normalize LUFS in a folder containing three audios, Music1.mp3, Music2.mp3 and Music3.mp3 using the double-pass method.
The LUFS and True Peak values are the same for all audio files:
LUFS -10.0 and True Peak -0.5
Code:
md "C:\Users\%username%\Desktop\Temp_normalizing_lufs" ------> temp folder audio files being normalized
pushd "%Userprofile%\Desktop\Audios LUFS" ------> folder with the original audio files
__
FOR /F "delims=" %%a in ('where .:*.mp3 ^|findstr /vi "_LOUDNORM _EBU"') DO ( |
SET "filename=%%~na" |
ffmpeg -hide_banner -i "%%a" -af "[0:a]loudnorm=print_format=summary" -f null NUL 2> "%%~na.log" |
@FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Integrated" "%%~na.log"') DO (SET II=%%b) |
@FOR /F "tokens=4" %%b IN ('FINDSTR /C:"Input True Peak" "%%~na.log"') DO (SET ITP=%%b) | set original audio files values
@FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input LRA" "%%~na.log"') DO (SET ILRA=%%b) | to use as parameters in loudnorm
@FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Input Threshold" "%%~na.log"') DO (SET IT=%%b) |
@FOR /F "tokens=3" %%b IN ('FINDSTR /C:"Target Offset" "%%~na.log"') DO (SET TO=%%b) |
DEL "%%~na.log" __|
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "tokens=1,2 delims=," %%b IN ('ffprobe -v 0 -select_streams a -show_entries "stream=bit_rate,sample_rate" -of "csv=p=0" "!filename!.mp3"') ----> getting the sample rate and bitrate of the original audio file to use as parameters in loudnorm
DO (
ffmpeg -hide_banner -i "!filename!.mp3" -af "loudnorm=linear=true:I=!-10.0!:LRA=11:tp=!-0.5!:measured_I=!II!:measured_LRA=!ILRA!:measured_tp=!ITP!:measured_thresh=!IT!:offset=!TO!:print_format=summary" -c:v copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -acodec mp3 -b:a %%c -ar:a %%b "C:\Users\%username%\Desktop\Temp_normalizing_lufs\!filename!.mp3"
)
ENDLOCAL
)
xcopy "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.mp3" "C:\Users\%username%\Desktop\Normalized Audios Lufs\LOUDNORM\MP3\LUFS %-10.0%" /y /s /i ----> copying the audio files from the temporary folder to the final folder
__
del /q "C:\Users\%username%\Desktop\Temp_normalizing_lufs\*.*" |
rmdir "C:\Users\%username%\Desktop\Temp_normalizing_lufs" /s /q | Removing the temporary folder from the desktop
__|
Result of the Music1 audio file:
Input Integrated: -13.3 LUFS
Input True Peak: +1.6 dBTP
Input LRA: 6.1 LU
Input Threshold: -23.4 LUFS
Output Integrated: -11.8 LUFS
Output True Peak: -0.5 dBTP
Output LRA: 4.5 LU
Output Threshold: -21.9 LUFS
Normalization Type: Dynamic
Target Offset: +1.8 LU
Why doesn't the above value in the Output Integrated reach the LUFS of -10.0?
PS: even if I change the LUFS to -9.0, the Intregede Output value remains the same -11.8 LUFS.
I analyzed the Music1 audio using the volumedetect function, see the results below:
Output #0, null, to 'NUL':
Metadata:
title : Music1
TKEY : F#m
comment :
album : Electro's Remix
genre : Electro
artist : Chic
encoder : Lavf59.17.102
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Metadata:
encoder : Lavc59.21.100 pcm_s16le
size=N/A time=00:00:00.02 bitrate=N/A speed=2.61e+04x
size=N/A time=00:04:30.26 bitrate=N/A speed= 541x
size=N/A time=00:05:44.60 bitrate=N/A speed= 543x
video:0kB audio:59364kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_volumedetect_0 @ 0000022928c2e1c0] n_samples: 30394368
[Parsed_volumedetect_0 @ 0000022928c2e1c0] mean_volume: -15.7 dB
[Parsed_volumedetect_0 @ 0000022928c2e1c0] max_volume: 0.0 dB
[Parsed_volumedetect_0 @ 0000022928c2e1c0] histogram_0db: 13190
[Parsed_volumedetect_0 @ 0000022928c2e1c0] histogram_1db: 37702
In the result above that the max_volume parameter has a value of 0.0 dB.
Could this be the problem with normalization not reaching -10.0 that I set?
I applied a compressor in Music1 with the parameters:
Threshold: -25.00 db
Ratio : 2.00:1
Attack : 0.25 ms
Release: 20.0 ms
The result of the volumedetect function was:
Output #0, null, to 'NUL':
Metadata:
title : Music1
TKEY : F#m
comment :
album : Electro's Remix
genre : Electro
artist : Chic
encoder : Lavf59.17.102
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Metadata:
encoder : Lavc61.5.104 pcm_s16le
[Parsed_volumedetect_0 @ 0000021002da5180] n_samples: 30392156
[Parsed_volumedetect_0 @ 0000021002da5180] mean_volume: -17.1 dB
[Parsed_volumedetect_0 @ 0000021002da5180] max_volume: -0.9 dB
[Parsed_volumedetect_0 @ 0000021002da5180] histogram_0db: 2
[Parsed_volumedetect_0 @ 0000021002da5180] histogram_1db: 9
Note above that the max_volume value has changed to -0.9 db
I performed audio normalization with the parameter LUFS = -10.0
and the True Peak = -0.0
:
Input Integrated: -14.6 LUFS
Input True Peak: -0.7 dBTP
Input LRA: 4.6 LU
Input Threshold: -24.6 LUFS
Output Integrated: -10.5 LUFS
Output True Peak: +0.0 dBTP
Output LRA: 3.8 LU
Output Threshold: -20.5 LUFS
Normalization Type: Dynamic
Target Offset: +0.5 LU
Note above that the result of Output Integration was much better.
Results of the Music2 audio file:
Input Integrated: -6.0 LUFS
Input True Peak: +4.9 dBTP
Input LRA: 4.8 LU
Input Threshold: -16.3 LUFS
Output Integrated: -10.0 LUFS
Output True Peak: -0.5 dBTP
Output LRA: 4.3 LU
Output Threshold: -20.3 LUFS
Normalization Type: Dynamic
Target Offset: +0.0 LU
Results of the Music3 audio file:
Input Integrated: -5.9 LUFS
Input True Peak: +0.6 dBTP
Input LRA: 4.5 LU
Input Threshold: -16.0 LUFS
Output Integrated: -10.0 LUFS
Output True Peak: -3.5 dBTP
Output LRA: 4.5 LU
Output Threshold: -20.1 LUFS
Normalization Type: Linear
Target Offset: -0.0 LU
Why in the above audio files, Music2 uses Normalization Type: Dynamic and Music3 uses Normalization Type: Linear?... what rule defines when it is Dynamic and when it is Linear?
-16.0
Output Threshold to -21.8 LUFS
... I think this audio must have some limitation that doesn't allow it to reach -10.0 LUFS!.1
difference. Yeah, that's an weird one. Are the mp3's 44100? Try.wav
. You could try converting them to PCM 16-bit 48000k. That will give you more frequency range for potential adjustment.normalize
and then return the wav to mp3 with 44100? Ps: I need the audio in mp3, ok?