Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normalize audio in an avi file

I have an avi file that has different levels of audio. Is there a way to decrease and increase appropriately where needed the audio of my file using ffmpeg?

like image 398
zinon Avatar asked Jun 10 '14 16:06

zinon


People also ask

How do I normalize audio in a video?

Right-click on the video in the track and select the option and in the context menu that appears, select "Audio functions" > "Normalize (maximum level)".

Should I normalize when exporting audio?

There's is almost NO reason to normalize audio ever. If you need it louder for whatever reason, learn how to use a limiter instead. And even if you do that, don't make it TOO loud if it's going to an artist or studio to have vocals recorded over it.


1 Answers

In ffmpeg you can use the volume filter to change the volume of a track. Make sure you download a recent version of the program.

Find out the gain to apply

First you need to analyze the audio stream for the maximum volume to see if normalizing would even pay off:

ffmpeg -i video.avi -af "volumedetect" -f null /dev/null

Replace /dev/null with NUL on Windows. This will output something like the following:

[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] mean_volume: -16.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] max_volume: -5.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] histogram_0db: 87861

As you can see, our maximum volume is -5.0 dB, so we can apply 5 dB gain. If you get a value of 0 dB, then you don't need to normalize the audio.

Apply the volume filter:

Now we apply the volume filter to an audio file. Note that applying the filter means we will have to re-encode the audio stream. What codec you want for audio depends on the original format, of course. Here are some examples:

Plain audio file: Just encode the file with whatever encoder you need:

ffmpeg -i input.wav -af "volume=5dB" output.mp3

Your options are very broad, of course.

AVI format: Usually there's MP3 audio with video that comes in an AVI container:

ffmpeg -i video.avi -af "volume=5dB" -c:v copy -c:a libmp3lame -q:a 2 output.avi

Here we chose quality level 2. Values range from 0–9 and lower means better. Check the MP3 VBR guide for more info on setting the quality. You can also set a fixed bitrate with -b:a 192k, for example.

MP4 format: With an MP4 container, you will typically find AAC audio. We can use ffmpeg's build-in AAC encoder.

ffmpeg -i video.mp4 -af "volume=5dB" -c:v copy -c:a aac -strict experimental -b:a 192k output.mp4

Here you can also use other AAC encoders. Some of them support VBR, too. See this answer and the AAC encoding guide for some tips.

In the above examples, the video stream will be copied over using -c:v copy. If there are subtitles in your input file, or multiple video streams, use the option -map 0 before the output filename.

The author's info is: Jon Skarpeteig in SuperUser

like image 171
Cibrán Docampo Avatar answered Oct 19 '22 22:10

Cibrán Docampo