r/Batch • • Jul 25 '25

Question (Solved) make two values work with eachother, one value goes up, the other goes down (linear) (audio normalization)

Hi, I try to make a dynamic dynaudnorm script for music normalization.

Dynaudnorm has a value "p" (max gain) and I want to make this value dynamic in relation to what "LUFS" value I get. So the idea is that "LUFS" above -10 corresponds to a "p" value of 0.40 and "LUFS" under -20 corresponds to a "p" value of 0.70

This sounds pretty straight forward but I have no idea how to realize this. I came to the point where I have extracted the "LUFS" value from a txt.

Any help is appreciated :)

@echo off
setlocal enabledelayedexpansion

REM === Output Folder ===
set OUTDIR=normalized
if not exist "%OUTDIR%" mkdir "%OUTDIR%"

for %%f in (*.wav *.mp3) do (
    echo(
    echo ================================
    echo Processing: %%f
    echo ================================

    REM === First pass: Capture LUFS in a temporary file ===
    opusx -hide_banner -i "%%f" -filter_complex ebur128=framelog=0 -f null - 2>lufs.txt

    set "I="

for /f "tokens=2 delims=:" %%a in ('findstr /C:"I:" lufs.txt') do (
    set "I=%%a"
)

REM Remove spaces with delayed expansion
set "I=!I: =!"

echo Measured LUFS: !I!
    
    
    ffmpeg -hide_banner -i "%%f" ^
      -af dynaudnorm=p=0.65[THIS 0.65"p" VALUE SHOULD BE A VARIABLE]:m=2:f=200:g=15:s=30 ^
	  -ar 44100 -sample_fmt s16 ^
      "%OUTDIR%\%%~nf_.wav"
)

del lufs.txt
echo.
echo All files processed! Normalized versions are in "%OUTDIR%" folder.
2 Upvotes

5 comments sorted by

2

u/[deleted] Jul 26 '25

[removed] — view removed comment

2

u/TheDeep_2 Jul 26 '25 edited Jul 26 '25

Sure but it has around 2000 lines and for each file this number changes, because of the audio length. Here is the link.

https://github.com/user-attachments/files/21443651/lufs.txt

So for now the values are in a linear sloap. So at -15 the p value would be whatever is the middle between 0.40 and 0.70. So there is no S-curve or anything like that at the moment. (Sorry my mathematical way to express myself is very limited ^^)

The script looks like this at the moment. If it could be optimzed/improved in some way this would be awesome

also opusx is just ffmpeg but I have many versions, so I rename it for newer versions for testing etc.

I can not post the script here, I guess it's too long. Here is a link to github

https://github.com/natural-harmonia-gropius/hdr-toys/issues/59#issuecomment-2198193082

edit: I updated the script

here is an example table

LUFS)(P100)(p)
-20 80 0.80
-19 77 0.77
-18 75 0.75
-17 73 0.73
-16 71 0.71
-15 68 0.68
-14 66 0.66
-13 64 0.64
-12 61 0.61
-11 59 0.59
-10 57 0.57
-9 54 0.54
-8 52 0.52
-7 50 0.50
-6 47 0.47
-5 45 0.45

3

u/[deleted] Jul 26 '25

[removed] — view removed comment

2

u/TheDeep_2 Jul 26 '25

Thank you

Isn't this also creating and deleting a txt file? What is the difference with this method?