I am currently working on a script to help me batch convert and normalize audio files (wma to mp3) In the search of useful tools I was lucky to stumble on FFMPEG-Normalize!
My script is running from Python and I am calling FFMPEG via subprocess. I could not get the FFMPEG-Normalize to output Mp3 files - thus I am doing another FFMPEG call to convert the resulted wav files. Do you know how to make FFMPEG normalize also convert to mp3 ? The second issue is that only part of the files in my folder are being processed, I cant understand why. Out of 8 files I have in the path, sometimes all of them are processed and sometimes only 3, or 5... very weird! Here is my code :
for file in sorted(os.listdir(pathdes)):
os.chdir(pathdes)
subprocess.call(['ffmpeg-normalize','-m','-l','-0.1',file])
file = 'normalized-' + file
file = file[:-3] + "wav"
file2 = file[:-3] + "mp3"
os.chdir(pathdes)
subprocess.call(['ffmpeg', '-i', file,'-b:a','320k', file2])
I understand FFMPEG normalize was written in Python, maybe there is another way to call it other than subprocess ? Am I missing something ? (i know i am !)
Thank you so much !
The ffmpeg-normalize
tool allows you to set an audio encoder as well, using the -a
, --acodec <acodec>
option.
For example, to EBU R128-normalize a bunch of WAV files and encode them to MP3 with libmp3lame
:
ffmpeg-normalize --ebu --acodec libmp3lame --extra-options "-b:a 192k" *.wav
Note that for MP3 specifically, you could use MP3Gain to change the volume without having to re-encode the files.