FreshPeppa
FreshPeppa

Reputation: 31

Python - How to normalize audio in a video file?

By "normalize," I mean "increase/decrease the overall volume so that the maximum reaches maximum headroom."

I'm part of my school's news crew and teachers send commercials in, but they are often too loud or too soft. I'd like to create a program the normalizes the audio (no compression or limiting). It would generally have to work with .mov and .wmv files. Can anyone guide me toward some good tutorials, libraries, etc.?

Upvotes: 0

Views: 2027

Answers (1)

bobince
bobince

Reputation: 536349

Demultiplexing the audio stream out of the AV container and decompressing it: you'll want a wrapper for the ffmpeg library. eg try pyffmpeg, AVbin, pymedia.

Normalizing: use a Numpy array of per-sample integers, find the max then multiply the array to amplify/attenuate volume. Consider using ReplayGain.

Recompressing the audio and remultiplexing with the original video stream into a new container: same libraries as above, but more likely to cause difficulties, especially for proprietary containers and codecs. (eg I believe ffmpeg can only produce a really old WMA version.)

It's not going to be straightforward and I'm not sure it will necessarily be worth it, in comparison with using a readymade app. For example ffmpeg itself has a command line you could batch script, and eg avidemux has both command line and GUI interfaces.

Also, I suspect you'll find simple peak normalisation won't get you very far in terms of making effective volume levels similar; usually you'll need to use some quantity of dynamic range compression too.

Upvotes: 2

Related Questions