How do I filter the audio of multiple mp4 video files using FFmpeg to make them louder

Hi everyone,

I have FFmpeg installed on my Manjaro xfce system and I would like to know how to adjust the volume of multiple video files at once to make them louder, similar to the Add To Queue button in Handbrake. Please bear with me, I’m quite a newbie. At most I can adjust the volume of a single file.

I found this article: How to Adjust Volume Using FFmpeg (Volume, DRC, Normalization included) - OTTVerse which says it can be done through a bash script. I am hoping someone can guide me through this.

The command in the article is

#!/bin/bash for file in *.mp4; do ffmpeg -i "$file" -af "volume=3dB" "output_$file" done

Can I use the Manjaro terminal for a bash script or do I need to use another text editor? I had assumed I open the Manjaro terminal, change to the directory housing my video files and enter the command. I can’t seem to succeed that way, I think a big gap in my understanding of how to do this.

In the command itself, do I replace $file with ${my filename} and output_$f with {myoutputname}_$f

Any help would be greatly appreciated. Thank you.

Just run it from a terminal within the directory. Make sure you leave the #!/bin/bash off at the start though if running from the command line, as the # will make it look like a comment to be ignored.

An alternative might be to use aacgain, which is in the AUR. It can adjust the volume of files in a process which is reversible at any time, and all files can be set to the same volume. aacgain is a modification to mp3gain which can be used on mp4 files. Make sure you read the mp3gain instructions link below before using aacgain though:

1 Like

Hi scotty65

Thanks for your help.

I can’t seem to get it right. When I type that command nothing happens except that I get a > sign .

There’s a typo in the original command - it is missing a semi-colon before the “done” at the end. Try this:

for file in *.mp4; do ffmpeg -i "$file" -af "volume=3dB" "output_$file"; done
1 Like

Ah, perfect! Now it works!

Thank you so much.

Does it also work for.mkv same way?

It should, since the ffmpeg command doesn’t specify an audio codec.

Maybe you should copy a few of your mkv files across to a test directory and run the command in the test directory to see if it works. If it doesn’t, ffmpeg should show in the terminal what the problem is.

1 Like

Thanks, scotty65. It’s working .

I appreciate your help.

1 Like

VLC has an option to Normalise volume in audio settings
There is also a compressor plugin in advanced settings to reduce the dynamic range

For levelling live audio I usually use vlevel-gitAUR compressor+limiter

There is also MKVToolNix which is handy for Matroska (.mkv) files; which allows to separate and export the audio track, and remux it later.

It’s not an elegant or easy solution, however, it is a powerful application for manipulating Matroska files. A brief look at MKVToolNix capabilities will reveal just how useful it can be:

Cheers.

1 Like

Audio filter volumedetect should be used to check audio levels before using volume filter tc change the level

ffmpeg -i $file -filter:a volumedetect -f null /dev/null

I also suggest trying the loudnorm filter that can give more consistent results (EBU R128 broadcast standard) and the ffmpeg-normalize python script for ffmpeg

trac.ffmpeg.org/wiki/AudioVolume
GitHub - slhck/ffmpeg-normalize: Audio Normalization for Python/ffmpeg
https://superuser.com/questions/323119/how-can-i-normalize-audio-using-ffmpeg

Thank you nikgnomic and soundofthunder.

I will check out all those suggestions.

Thanks, scotty65.

Two questions:

  1. It works when I copy the command directly but I can’t seem to get it right when I type out the command myself. This could be just my inexperience and making typo or spacing errors etc, but is there maybe something extra embedded in the command you posted that a plain text command can’t do (excuse my ignorance, the different colours on $file, etc)?

  2. Using ffmpeg this way seems to shrink the file size of the video slightly. I actually thought only the audio would be re-encoded. What is ffmpeg actually doing?

Thanks.

I don’t have an answer as I don’t know what you are manually typing in the terminal, but there is definitely nothing extra embedded in the command (which was originally provided by you, not me. I just added a missing semicolon to fix it).

Maybe it is re-encoding - I don’t use ffmpeg to adjust volume. I use mp3gain to adjust the volume on mp3s, and aacgain (apparently) does the same thing for mp4s. mp3gain doesn’t re-encode, it just adds a tag to the file metadata telling compatible players to increase or lower the volume of the file (and thus also makes the changes reversible). aacgain does the same thing.

That is why I recommended that you try aacgain (although I’ve never used it myself - I just scroll the mouse wheel on the volume icon in my system tray if a video is too loud or quiet).

aacgain should be very simple & very fast, but you will have to do some reading at the links I provided in post 2 of this thread. I just don’t have the time to coach you through the process. The mp3gain instructions (especially the command line section) are required reading because the author of aacgain says it uses the same commands (except with aacgain instead of mp3gain at the start).

Thank you again for taking the time to help me. Much appreciated.

1 Like

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.