CLI Fix Audio Level on Video Files

Sometimes you have video files that have very quiet audio and this simple command line bash script will find how much gain it can add to the file without clipping and apply it for you.

fix-audio-levels <filename>

fix-audio-levels s01e02.mp4

ffmpeg apply audio gain...
219M s02e08.mp4.old
231M s02e08.mp4


To install this simply run (ideally in a folder that is in your path like /usr/local/bin or ~/bin if you have one)

curl -o fix-audio-levels && chmod +x fix-audio-levels

View on github

Also make sure you have ffmpeg installed.

How it works

This script uses ffmpeg and does a first pass to find the max volume. A bunch of regex processing of the stderror (yeah, all ffmpeg output is sent to stderror and its easiest to redirect it to a file which also adds a nice caching effect). Now we copy the file, just incase something bad happens. Then we normalize the audio with the audio gain value we found on a second pass to process the audio with the gain.

If all is good, you can delete the .old file (and the .ffmpegoutput if you want) and enjoy your fixed audio file.

openanalytics 174584 views

I'm a 35 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.

View Comments
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.