I’m still driving myself crazy trying to test & correct audio volume problems on AVI files. I have a number of videos (using MP3 audio) with either too low or too high an audio volume and I’m looking to normalize them.
Is there a command line for FFMPEG or some other program to compare a file to a Target ‘Normal’ of 89 DB? I would like it to give an indication of how many DB’s are necessary to bring it up or down to 89.
Thanks in advance,
John
		
			+ Reply to Thread
			
		
		
		
			
	
	
				Results 1 to 7 of 7
			
		- 
	
- 
	it might be possible to archive something like this using sox, but it will require a lot of reading of the sox manual (http://sox.sourceforge.net/sox.html) 
 
 will return something like (here for a stereo source):Code:ffmpeg -y -analyzeduration 500000000 -v -10 -i "Path to file" -f sox - | sox --multi-threaded --buffer 524288 -S -t sox - -n stats 
 if you don't want the statistics per channel:Code:Overall Left Right DC offset 0.000001 0.000001 0.000000 Min level -0.157471 -0.157471 -0.156433 Max level 0.119263 0.117676 0.119263 Pk lev dB -16.06 -16.06 -16.11 RMS lev dB -42.19 -42.15 -42.23 RMS Pk dB -32.12 -32.12 -32.26 RMS Tr dB -62.14 -62.14 -62.13 Crest factor - 20.16 20.22 Flat factor 0.00 0.00 0.00 Pk count 2 2 2 Bit-depth 14/16 14/16 14/16 Num samples 824k Length s 17.160 Scale max 1.000000 Window s 0.050 
 will return something like:Code:ffmpeg -y -analyzeduration 500000000 -threads 8 -v -10 -i "Path to file" -f sox - | sox --multi-threaded --buffer 524288 -S -t sox - -n stat 
 based on these statistics it should be possible to calculate the amount in gain is needed to reach 89db,...Code:Samples read: 1647360 Length (seconds): 17.160000 Scaled by: 2147483647.0 Maximum amplitude: 0.119263 Minimum amplitude: -0.157471 Midline amplitude: -0.019104 Mean norm: 0.003803 Mean amplitude: 0.000001 RMS amplitude: 0.007773 Maximum delta: 0.097717 Minimum delta: 0.000000 Mean delta: 0.001382 RMS delta: 0.002022 Rough frequency: 1987 Volume adjustment: 6.350 Done. 
 
 ffmpegs volumedetect:
 returns something like:Code:ffmpeg -y -analyzeduration 500000000 -threads 8 -i "Path to input" -af volumedetect -f null - 
 if you do this for each file, you get the max volume for each file, which should allow you to calculate the amount of volume gain per file that you want,..Code:[Parsed_volumedetect_0 @ 0000000000340b00] n_samples: 1647360 [Parsed_volumedetect_0 @ 0000000000340b00] mean_volume: -42.2 dB [Parsed_volumedetect_0 @ 0000000000340b00] max_volume: -16.1 dB Last edited by Selur; 24th Apr 2013 at 05:46. 
- 
	For "normalizing" audio from my videos, I demux and convert to WAV, then use WaveGain to set the volume, then encode to AC3 and remux. I have BAT files to do all this for me, of course. WaveGain defaults to -3 decibels, I believe, but you can override that to get to your desired loudness. Download WaveGain 1.3.1 from - http://www.rarewares.org/others.php 
- 
	Time has moved on a bit with ffmpeg. 
 I am seeking to adjust loudness and convert to .mp2 via .bat files and ffmpeg (only).
 The outputs from these look interesting:
 If I can somehow in DOS crack out the value from lines in those files into variables, egCode:".\ffmpeg.exe" -y -vn -nostats -threads 8 -i ".\test.mpg" -af volumedetect -f null - > vol.max.txt 2>&1 ".\ffmpeg.exe" -y -vn -nostats -threads 8 -i ".\test.mpg" -filter_complex ebur128 -f null - > vol.ebur128.txt 2>&1 
 in this case into VOLM=-7.7[Parsed_volumedetect_0 @ 049ae8a0] max_volume: -7.7 dB
 and
 in this case into VLUFS=-25.1I: -25.1 LUFS
 
 and then, in DOS, calculate
 adjVOLM=min(abs(VOLI),16)
 adjLUFS= min(abs(max(-23-VLUFS),0)),16)
 
 Then I can choose which to use for ffmpeg volume adjustment
 egper https://forum.videohelp.com/threads/352067-normalizing-audio-volume-using-new-ffmpeg-op...=1#post2209591Code:ffmpeg ...volume=volume=%myvariabe%dB:precision=float ... 
 and
 http://ffmpeg.mplayerhq.hu/ffmpeg-filters.html#volume
 
 I'm not really sure whether to use the LUFS number or the max loudness number from "-af volumedetect"
 
 Suggestions sought on a simpler way to do it, or pointers on how to
 (a) read and crack out the values from the text files, using DOS
 (b) do the calculations in DOS
 
 Meanwhile, I'll continue googling...Last edited by hydra3333; 2nd Dec 2013 at 23:14. 
- 
	Alright, brute force and a lot of ignorance then. 
 Looking forward to a slimline suggestion from someone smarter 
 Code:@echo off @setlocal ENABLEDELAYEDEXPANSION @echo on SET volFile=.\max.vol.vol.txt ".\ffmpeg.exe" -y -vn -nostats -threads 8 -i ".\test.mpg" -af volumedetect -f null - > %volFile% 2>&1 SET vbsf_vol=".\000-f1.vol.vbs" REM @echo off ECHO ' read vol from ffmpeg file and return the Maximum Volume value only > %vbsf_vol% ECHO Const ForReading = 1 >> %vbsf_vol% ECHO Dim objStdOut, objFSO , objFile, line, e, s, v, adj, er >> %vbsf_vol% ECHO 'Set objStdOut = WScript.StdOut >> %vbsf_vol% ECHO Set objFSO = CreateObject("Scripting.FileSystemObject") >> %vbsf_vol% ECHO Set objFile = objFSO.OpenTextFile("!volFile!", ForReading) >> %vbsf_vol% ECHO er = 1 >> %vbsf_vol% ECHO v = 0 >> %vbsf_vol% ECHO adj = 0 >> %vbsf_vol% ECHO Do Until objFile.AtEndOfStream >> %vbsf_vol% ECHO line = lcase(objFile.ReadLine) >> %vbsf_vol% ECHO if instr(line,lcase("max_volume:")) > 0 then >> %vbsf_vol% ECHO s = instr(line,lcase("max_volume:")) + 11 >> %vbsf_vol% ECHO e = instr(line,lcase("dB")) - 1 >> %vbsf_vol% ECHO 'WScript.StdOut.WriteLine "line=" ^& line >> %vbsf_vol% ECHO 'WScript.StdOut.WriteLine s ^& " " ^& e >> %vbsf_vol% ECHO if s^<=0 or e^<=0 then >> %vbsf_vol% ECHO exit do >> %vbsf_vol% ECHO end if >> %vbsf_vol% ECHO v = trim(mid(line,s,e-s+1)) >> %vbsf_vol% ECHO 'WScript.StdOut.WriteLine "string v=" ^& v >> %vbsf_vol% ECHO v = cdbl(v) >> %vbsf_vol% ECHO 'WScript.StdOut.WriteLine "cdbl v=" ^& v >> %vbsf_vol% ECHO adj = min(abs(v),16) >> "%vbsf_vol%" ECHO adj = max(adj-1,0) >> "%vbsf_vol%" ECHO 'WScript.StdOut.WriteLine "adj=" ^& adj >> %vbsf_vol% ECHO er = 0 >> %vbsf_vol% ECHO exit do >> %vbsf_vol% ECHO end if >> %vbsf_vol% ECHO Loop >> %vbsf_vol% ECHO WScript.StdOut.WriteLine adj >> %vbsf_vol% ECHO objFile.Close >> %vbsf_vol% ECHO set objFile = nothing >> %vbsf_vol% ECHO set objFSO = nothing >> %vbsf_vol% ECHO wscript.quit(er) ' 1=error. 0=ok >> %vbsf_vol% ECHO function Max(a,b) >> %vbsf_vol% ECHO Max = a >> %vbsf_vol% ECHO If b ^> a then Max = b >> %vbsf_vol% ECHO end function >> %vbsf_vol% ECHO function Min(a,b) >> %vbsf_vol% ECHO Min = a >> %vbsf_vol% ECHO If b ^< a then Min = b >> %vbsf_vol% ECHO end function >> %vbsf_vol% for /f "tokens=*" %%i in ('cscript //B //NOLOGO %vbsf_vol%') do set adjVOL=%%i ECHO The value adjVOL=!adjVOL! pause @echo on set ebur128File=max.vol.ebur128.txt ".\ffmpeg.exe" -y -vn -nostats -threads 8 -i ".\test.mpg" -filter_complex ebur128 -f null - > %ebur128File% 2>&1 SET vbsf_ebur128=".\000-f1.ebur128.vbs" @echo off ECHO ' read ebur128 from ffmpeg file and return the Integrated Loudness I value only > %vbsf_ebur128% ECHO Const ForReading = 1 >> %vbsf_ebur128% ECHO Dim objStdOut, objFSO , objFile, line, e, s, v, adj, er >> %vbsf_ebur128% ECHO 'Set objStdOut = WScript.StdOut >> %vbsf_ebur128% ECHO Set objFSO = CreateObject("Scripting.FileSystemObject") >> %vbsf_ebur128% ECHO Set objFile = objFSO.OpenTextFile("!ebur128File!", ForReading) >> %vbsf_ebur128% ECHO er = 1 >> %vbsf_ebur128% ECHO v = 0 >> %vbsf_ebur128% ECHO adj = 0 >> %vbsf_ebur128% ECHO Do Until objFile.AtEndOfStream >> %vbsf_ebur128% ECHO line = lcase(objFile.ReadLine) >> %vbsf_ebur128% ECHO if instr(line,lcase("Integrated loudness:")) > 0 then >> %vbsf_ebur128% ECHO line = lcase(objFile.ReadLine) >> %vbsf_ebur128% ECHO s = instr(line,lcase("I:")) + 2 >> %vbsf_ebur128% ECHO e = instr(line,lcase("LUFS")) - 1 >> %vbsf_ebur128% ECHO 'WScript.StdOut.WriteLine "line=" ^& line >> %vbsf_ebur128% ECHO 'WScript.StdOut.WriteLine s ^& " " ^& e >> %vbsf_ebur128% ECHO if s^<=0 or e^<=0 then >> %vbsf_ebur128% ECHO exit do >> %vbsf_ebur128% ECHO end if >> %vbsf_ebur128% ECHO v = trim(mid(line,s,e-s+1)) >> %vbsf_ebur128% ECHO 'WScript.StdOut.WriteLine "string v=" ^& v >> %vbsf_ebur128% ECHO v = cdbl(v) >> %vbsf_ebur128% ECHO 'WScript.StdOut.WriteLine "cdbl v=" ^& v >> %vbsf_ebur128% ECHO v = -23 - v >> %vbsf_ebur128% ECHO 'WScript.StdOut.WriteLine "-23-v v=" ^& v >> %vbsf_ebur128% ECHO adj = min(abs(max(v,0)),16) >> %vbsf_ebur128% ECHO 'WScript.StdOut.WriteLine "adj=" ^& adj >> %vbsf_ebur128% ECHO er = 0 >> %vbsf_ebur128% ECHO exit do >> %vbsf_ebur128% ECHO end if >> %vbsf_ebur128% ECHO Loop >> %vbsf_ebur128% ECHO WScript.StdOut.WriteLine adj >> %vbsf_ebur128% ECHO objFile.Close >> %vbsf_ebur128% ECHO set objFile = nothing >> %vbsf_ebur128% ECHO set objFSO = nothing >> %vbsf_ebur128% ECHO wscript.quit(er) ' 1=error. 0=ok >> %vbsf_ebur128% ECHO function Max(a,b) >> %vbsf_ebur128% ECHO Max = a >> %vbsf_ebur128% ECHO If b ^> a then Max = b >> %vbsf_ebur128% ECHO end function >> %vbsf_ebur128% ECHO function Min(a,b) >> %vbsf_ebur128% ECHO Min = a >> %vbsf_ebur128% ECHO If b ^< a then Min = b >> %vbsf_ebur128% ECHO end function >> %vbsf_ebur128% for /f "tokens=*" %%i in ('cscript //B //NOLOGO %vbsf_ebur128%') do set adjLUFS=%%i ECHO The value adjLUFS=!adjLUFS! pause exitLast edited by hydra3333; 3rd Dec 2013 at 06:26. 
Similar Threads
- 
  ? normalizing audio volume using new ffmpeg optionsBy hydra3333 in forum AudioReplies: 6Last Post: 2nd Dec 2013, 23:08
- 
  What is the ffmpeg command to merge two mono audio streams into one stereo?By Iced Coffee in forum Video ConversionReplies: 1Last Post: 10th Feb 2013, 23:54
- 
  FFMPEG command to argumentsBy wolfox in forum ProgrammingReplies: 4Last Post: 22nd Oct 2012, 03:33
- 
  ffmpeg generate audio/add to video help please, command lineBy surfmonkee in forum LinuxReplies: 3Last Post: 11th Sep 2011, 17:17
- 
  Help with FFMPEG command linesBy ricardouk in forum Video ConversionReplies: 11Last Post: 17th May 2008, 13:27


 
		
		 View Profile
				View Profile
			 View Forum Posts
				View Forum Posts
			 Private Message
				Private Message
			 
 
			
			 
			

 Quote
 Quote Visit Homepage
				Visit Homepage
			