Multi-audio file volume equalization program developed based on ffmpeg

foreword

audio_balance

✨Multi-audio file volume equalization program developed based on ffmpeg✨

license python

project address

GitHub:https://github.com/Ikaros-521/audio_balance
gitee:https://gitee.com/ikaros-521/audio_balance

Instructions for use

Python: 3.9+
program depends on ffmpeg implementation. Please install ffmpeg first and configure it to environment variables before using it. (Official warehouse: https://github.com/FFmpeg/FFmpeg )
If you have installed the format factory locally, you can directly configure the installation path of the format factory into the environment variable path (the format factory comes with ffmpeg)
Note: Please clear it when using it out folder (that is, the folder where the audio is output)

use reference

1. Obtain the desired volume in decibels

Use get_mean_volume.pyto get the average volume of an audio file. Here, it is recommended to pass in an audio file with an appropriate volume that you think is suitable for obtaining information, as a benchmark.

# 打开cmd,在工程路径下运行以下命令,其中 data/origin.mp3 为需要解析的音频文件
python get_mean_volume.py data/origin.mp3

Command execution returns key content interception

[Parsed_volumedetect_0 @ 000001d73eb72840] n_samples: 5329246
[Parsed_volumedetect_0 @ 000001d73eb72840] mean_volume: -20.7 dB
[Parsed_volumedetect_0 @ 000001d73eb72840] max_volume: -2.0 dB
[Parsed_volumedetect_0 @ 000001d73eb72840] histogram_2db: 57
[Parsed_volumedetect_0 @ 000001d73eb72840] histogram_3db: 390
[Parsed_volumedetect_0 @ 000001d73eb72840] histogram_4db: 1226
[Parsed_volumedetect_0 @ 000001d73eb72840] histogram_5db: 3330
[Parsed_volumedetect_0 @ 000001d73eb72840] histogram_6db: 6770
id3v2_parse

data/origin.mp3 平均音量:-20.7dB

2. Perform multi-audio equalization

In step 1 we see that the mean_volume (average volume) of data\origin.mp3 is -20.7dB, we expect the volume to be -10dB.

# 打开cmd,在工程路径下运行以下命令
# 请依次传入 目标平均音量(默认-10dB,做为基准,实际不会调至此) 待处理音频路径(默认data\) 输出音频路径(默认out\)
python audio_balance.py -10 data\ out\

output after running

待处理音频路径:data\
输出音频路径:out\
目标平均音量:-10.0dB
待处理音频文件总数:4
out\data\1 创建成功
data\1\origin.mp3 平均音量:-20.7dB
ffmpeg -i data\1\origin.mp3 -filter:a "volume=10.7dB" out\data\1\origin.mp3
转换完毕,输出至:out\data\1\origin.mp3
data\high.mp3 平均音量:-11.1dB
ffmpeg -i data\high.mp3 -filter:a "volume=1.1dB" out\data\high.mp3
转换完毕,输出至:out\data\high.mp3
data\low.mp3 平均音量:-30.7dB
ffmpeg -i data\low.mp3 -filter:a "volume=20.7dB" out\data\low.mp3
转换完毕,输出至:out\data\low.mp3
data\origin.mp3 平均音量:-20.7dB
ffmpeg -i data\origin.mp3 -filter:a "volume=10.7dB" out\data\origin.mp3
转换完毕,输出至:out\data\origin.mp3
运行完毕
请按任意键继续. . .`

Then you can use get_mean_volume.pyto get the average volume of the output file to check the situation

3. View the audio information (average volume, etc.) under the folder in batches

In step 1 we only looked at one, if you think it looks a bit slow, the benchmark file needs to be referenced in batches, you can use this command

# 打开cmd,在工程路径下运行以下命令
# 请传入 需要获取平均音量的音频文件夹路径 是否只显示平均音量(是1 否0)
python get_mean_volume_plus.py data\ 1

output content

文件夹路径:data\
音频文件总数:4
data\1\origin.mp3 平均音量:-20.7dB
data\high.mp3 平均音量:-11.1dB
data\low.mp3 平均音量:-30.7dB
data\origin.mp3 平均音量:-20.7dB

reference documents

Idea reference : https://wenku.baidu.com/view/ac883e43986648d7c1c708a1284ac850ad02042e.html?wkts=1668941587940&bdQuery=python%E8%8E%B7%E5%8F%96%E9%9F%B3%E9%A2%91%E 9 %9F%B3%E9%87%8F%E5%A4%A7%E5%B0%8F
ffmpeg reference: https://blog.csdn.net/ternence_hsu/article/details/91407681
Traverse file reference: https:// blog.csdn.net/weixin_41521681/article/details/92768157

Guess you like

Origin blog.csdn.net/Ikaros_521/article/details/128032824