Jump to content

Find loudest sound of the video.


 Share

Go to solution Solved by Terenz,

Recommended Posts

I need to know the loudest sound is in a video file, I made tests with ffmpeg.exe more each time it returns a different value, one can say the name of another program able to return this information?

$File = @ScriptDir & "\test.mp4"
$vol = Run(@ComSpec & ' -i ffmpeg.exe -af volumedetect -f null -"' & $File & '"' , @ScriptDir, @SW_HIDE)
MsgBox(4096, "Test 1", $vol)

$File = @ScriptDir & "\test.mp4"
$vol = Run(@ComSpec & ' -i ffmpeg.exe  -af volumedetect -f null"' & $File & '"' , @ScriptDir, @SW_HIDE)
MsgBox(4096, "Test 2", $vol)

$File = @ScriptDir & "\test.mp4"
$vol = Run(@ComSpec & ' -i ffmpeg.exe  -af volumedetect -f"' & $File & '"' , @ScriptDir, @SW_HIDE)
MsgBox(4096, "Test 3", $vol)

$File = @ScriptDir & "\test.mp4"
$vol = Run(@ComSpec & ' -i ffmpeg.exe -af volumedetect "' & $File & '"' , @ScriptDir, @SW_HIDE)
MsgBox(4096, "Test 4", $vol)
Link to comment
Share on other sites

Run returns the PID of the process you start.  Which means that $vol in your code will most likely be a modestly large integer that goes up at each use.  You need to instruct the client to send back the standard out stream and capture that in a loop.  Then you need to read that.

I don't have ffmpeg, so I can't tell if this is correct, but it should get you started...

#include <Constants.au3>

$File = @ScriptDir & "\test.mp4"
$pid = Run(@ComSpec & ' -i ffmpeg.exe  -af volumedetect -f null"' & $File & '"' , @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
$data = ""
While True
    $data &= StdoutRead($pid)
    If @error Then ExitLoop
Wend

ConsoleWrite($data & @LF)
Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

It did not work with these commands as well.

 

> Running AU3Check (3.3.9.4) a partir de: C: Arquivos de Programas AutoIt3

+> 15:53:42 AU3Check ended.rc: 0
> Running: (3.3.9.4): C: Arquivos de Programas AutoIt3 autoit3.exe "E: Teste script.au3"    
-> Pressione Ctrl + Alt + F5 para reiniciar ou Ctrl + BREAK para interromper
Microsoft Windows XP [versÆo 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.
 
E: Teste>
+> 15:53:42 AutoIT3.exe ended.rc: 0
> Código de saída: 0 Tempo: 2.392

 

The DDVideoMP4Gain.exe program can show the highest sound of video files plus it does not accept command line to return the information I need, will have any dll able to return this information?

Edited by Belini
Link to comment
Share on other sites

Let me say this differently: I do not have or use ffmpeg.exe .  I have no idea how one would go about getting the loudest sound.  I have no idea if it's even possible - from any software anywhere - since this is not something I've ever attempted or even thought about.

HOWEVER, your first post output the PID of the process created, and couldn't possibly have shown the sound.  I was simply pointing that out.

I apologize if I misled you. :)

 

[EDIT] I should add that I was under the impression that if one were to run ffmpeg.exe  -af volumedetect -f null "test.mp4" that one would see the loudest sound output on the console.  And so consequently, I thought that all one had to do was correct the method used to get the output, and one would get the answer.

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

 I have no idea how one would go about getting the loudest sound.  I have no idea if it's even possible - from any software anywhere - 

 

Yes you can! DDVideoMP4Gain.exe can show the loudest sound of the video, Mp3Gain.exe shows the highest sound .mp3 and Mp3Gain.exe also normalizes all files in the same volume.

Link to comment
Share on other sites

Belini,

Before write something in Autoit you need to know what you do with the external software, like read the documentation.

-i = input_file, instead i see -i ffmpeg.exe :sweating: 

Anyway this is the working code, learn from it:

#include <Constants.au3>

$sFile = @ScriptDir & "\Test.mp4"
$iPID = Run(@ComSpec & " /c ffmpeg.exe -i " & '"' & $sFile & '"' & " -af volumedetect -f null NUL", @ScriptDir, @SW_HIDE, $STDERR_CHILD)
Local $sData = ""
Do
    $sData &= StderrRead($iPID)
Until @error
ConsoleWrite("--> DEBUG: " & @CR & $sData)
$aData = StringRegExp($sData, '(?:' & "max_volume: " & ')(.*?)(?:' & " dB" & ')', 3)
If IsArray($aData) Then MsgBox(0, "max_volume", $aData[0])

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Terrenz Thanks for replying, did tests with 3 files that have different levels of volume and still could not find the loudest sound of them, see the result:

 

File 83.8db = result: -0.9
File 88.1db = result: -1.8
File 102.9db = result: -0.0

 

Follow the link to download the files I testedhttps://www.dropbox.com/s/6ndfyr7x6ktp45e/Test_max_vol.rar?dl=0

Link to comment
Share on other sites

looks fine to me

 

I do not understand why a negative value is the highest sound and why sound files above 100dbs return -0!

Edited by Belini
Link to comment
Share on other sites

I used to see DDVideoMP4Gain.exe the loudest sound files and I can not get these same values, dbs of each file is in their name.

Archives test: https://www.dropbox.com/s/6ndfyr7x6ktp45e/Test_max_vol.rar?dl=0

Note: any program from the command line or dll to return this information will serve to me and not have to be just using ffmpeg.exe

Edited by Belini
Link to comment
Share on other sites

Belini,

What you what to do is called "peak normalization", meaning that it will make the loudest part in the file sit at 0 dB instead of something lower. In one of your example, the maximum volume is -0.9 dB, so you need apply 0.9 dB gain. If you get a value of 0 dB, then you don't need to normalize the audio. The command is:

-af volume=XdB

Where X is the value of dB. Is clear now? ;)

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

In this way it will not work because the files that give zero is precisely the highest 102dB and I want to standardize all to 89dB

Link to comment
Share on other sites

Ok, my last try. Download AACGain 1.9. From the commandline:

aacgain.exe path/of/the/102.9db.mp4

The output is:

Recommended "Track" dB change: -14.190000
Recommended "Track" mp3 gain change: -9
Max PCM sample at current gain: 47727.753906
Max mp3 global gain field: 186
Min mp3 global gain field: 100


Recommended "Album" dB change for all files: -14.190000
Recommended "Album" mp3 gain change for all files: -9

102.9 - 14.1 = 88.8 dB

For normalize the audio:

aacgain.exe /r path/of/the/102.9db.mp4

Or you can use your value, check the help of the commandline

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites




 
 

 



102.9 - 14.1 = 88.8 dB

 

If I had this information would be easy but in the example you posted when the louder the sound file is larger than 100dbs always returns -0.0.
 
Normalizar.jpg
 
I have more than 10.000 videos and most are already normalized 89dbs, I need the information to separate only the files that are to the sound below or above 89dbs
 

 

Link to comment
Share on other sites

  • Solution

No Belini you don't have understand  ;)

That calculation ( 102.9 - 14.1 ) was only to prove that AACGain work fine and give you the correct result because instead of the wrong 0.0 dB of ffmpeg, AACGain return -14.1 dB ( Recommended "Track" dB change: -14.190000 ) so you need to subtract that 14.1 value for have the 89 dB or make the AACGain automatically did for you with the /r parameter, you don't need to know how many decibel is the file, but you can easy know if you are intrested*

For example to the 83.8 file give:

Recommended "Track" dB change: 5.690000

Another correct result because adding 5.6 dB, i'll repeat you don't need to know the starting dB, normilize the audio to 89 dB.

* If the 89 is the default value, just add or subtract the "Recommended "Track" dB change" for know the dB of the file.

#include <Constants.au3>

$sFile = @ScriptDir & "\Test.mp4"
$iPID = Run(@ComSpec & " /c aacgain.exe " & '"' & $sFile & '"', @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
Local $sData = ""
Do
    $sData &= StdoutRead($iPID)
Until @error
ConsoleWrite("--> DEBUG: " & @CR & $sData)
$aData = StringRegExp($sData, '(?:' & 'Recommended "Track" dB change: ' & ')(.*?)(?:' & "0000" & ')', 3)

; How to get the dB of the file
If IsArray($aData) Then
    If StringInStr($aData[0], "-") Then
        MsgBox(0, "Volumn(dB)", 89 + StringReplace($aData[0], "-", ""))
    Else
        MsgBox(0, "Volumn(dB)", 89 - $aData[0])
    EndIf
EndIf
Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

You were right from the start and did not understand what you said, now I can do what I need, thanks for your help and patience.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...