Skip to content

Instantly share code, notes, and snippets.

@44213
Forked from xycui/VolumeDetect.md
Created September 18, 2021 08:43
Show Gist options
  • Save 44213/fcf779bc9f1faf0cacc585ae7d7b808a to your computer and use it in GitHub Desktop.
Save 44213/fcf779bc9f1faf0cacc585ae7d7b808a to your computer and use it in GitHub Desktop.
Use ffmpeg to detect audio volume level. bat file included for easier interaction.
@echo off
:begin
ECHO Drag the audio file here and press 'Enter' for the next step
set /p filePath=Audio file path:
"./ffmpeg.exe" -i %filePath% -filter:a volumedetect -f null /dev/null
echo.
goto begin
pause

Detect the audio file volume with ffmpeg.

Require tools

How to use

  1. Download ffmpeg from link
  2. Extract the ffmpeg.exe from zip package and copy to the directory contain the audio file
  3. Copy the volumeDetect.bat into the folder. (Just make sure the bat file and ffmpeg.exe are in the same directory)
  4. Doulbe click volumeDetect.bat and drag the file into the window.
  5. Press enter and get the result.

Result analyze

Find the key word: max_volume. 0.0dB should be treated as a benchmark.

Sample result:

ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mp3, from 'xiaoice1.mp3':
  Duration: 00:02:05.17, start: 0.069063, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 16000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : LAME3.99r
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Audio: pcm_s16le, 16000 Hz, stereo, s16, 512 kb/s
    Metadata:
      encoder         : Lavc57.107.100 pcm_s16le
size=N/A time=00:02:05.07 bitrate=N/A speed= 749x
video:0kB audio:7817kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_volumedetect_0 @ 000001bcb1412ea0] n_samples: 4002280
[Parsed_volumedetect_0 @ 000001bcb1412ea0] mean_volume: -19.7 dB
[Parsed_volumedetect_0 @ 000001bcb1412ea0] max_volume: -0.9 dB
[Parsed_volumedetect_0 @ 000001bcb1412ea0] histogram_0db: 2
[Parsed_volumedetect_0 @ 000001bcb1412ea0] histogram_1db: 21
[Parsed_volumedetect_0 @ 000001bcb1412ea0] histogram_2db: 146
[Parsed_volumedetect_0 @ 000001bcb1412ea0] histogram_3db: 505
[Parsed_volumedetect_0 @ 000001bcb1412ea0] histogram_4db: 1357
[Parsed_volumedetect_0 @ 000001bcb1412ea0] histogram_5db: 3200

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment