Log in

View Full Version : [Batch] Normalize using LoudNorm of FFmpeg


Overdrive80
23rd April 2019, 21:29
I had create script for windows user, that let drag'n'drop, for normalization in one pass using FFmpeg.

@ECHO OFF
TITLE Normalize audio using LoudNorm
COLOR E0

:begin
::Set ffmpeg path
SET "ffmpeg=%~dp0ffmpeg-4.1.1-win32-static\bin\ffmpeg.exe"
ECHO FFmpeg is set in path: '%ffmpeg:~0,-11%' & ECHO.

SET "iPath=%~dp1"
SET "input=%~nx1"

::Set file path to normalize
IF [%input%] == [] (
SET "iPath=C:\Users\Isra-PC\Desktop\Nueva carpeta\"
SET "input=Opening_BA.wav"
)

ECHO The file source to normalize is: '%input%' & ECHO.

GOTO MAIN

:main

ECHO The process has begin...&ECHO.

"%ffmpeg%" -hide_banner -nostdin -y -channel_layout stereo -i "%iPath%%input%" -af loudnorm=-16:TP=-1.5:LRA=11:print_format=json -c:a pcm_f32le -f null -y nul 2> volStats.txt

::measured_I
call :find "input_i"
set "measured_I=%ganancy%"
::echo %measured_I%

::measured_TP
call :find "input_tp"
set "measured_TP=%ganancy%"
::echo %measured_TP%

::measured_LRA
call :find "input_lra"
set "measured_LRA=%ganancy%"
::echo %measured_LRA%

::measured_thresh
call :find "input_thresh"
set "measured_thresh=%ganancy%"
::echo %measured_thresh%

::offset
call :find "target_offset"
set "offset=%ganancy%"
::echo %offset%

goto normalization

:Normalization
"%ffmpeg%" -hide_banner -nostdin -y -channel_layout stereo -i "%iPath%%input%" -af loudnorm=-16:TP=-1.5:LRA=11:measured_I=%measured_I%:measured_LRA=%measured_LRA%:measured_TP=%measured_TP%:measured_thresh=%measured_thresh%:offset=%offset%:linear=true:print_format=summary -c:a pcm_f32le -ar 48k %input:~0,-4%_normalized.wav

ECHO.
ECHO The process has ended. Press any key for exit. & pause>nul & exit

:find
set "paramSearch=%1"

for /F "tokens=3,* delims= " %%a in ('findstr "%paramSearch%" "%~dp0volStats.txt"') do (
set ganancy=%%a
)

set ganancy=%ganancy:,=%
set ganancy=%ganancy:~1,-1%

goto :eof

I hope that be useful. Enjoy!!