0

I want to implement the feature normalization of the audio of the video. I have done some R&D but did not find any appropriate solution.

I have also a doubt that do I have to fetch the audio from the video and then normalize it and then merge the audio in the video(which can be a time-consuming task) or I can directly normalize the video file?

Or if there is any specific FFmpeg command for the same, then I would love to use it.

3
  • For FFmpeg there's an EBU R 128 filter: ffmpeg.org/ffmpeg-filters.html#loudnorm. Or if you want to do it manually: trac.ffmpeg.org/wiki/AudioVolume. Both will require re-encoding the audio track. Commented Nov 25, 2021 at 10:04
  • Actually, I want to implement it for videos(.mp4) files. Is it possible to normalize the audio in the already recorded videos? Commented Nov 29, 2021 at 7:29
  • For compatibility with all players you can keep the encoded video track as it is and re-encode just the audio tracks. It might be possible to specify ReplayGain metadata instead if the player supports it during playback. Commented Nov 29, 2021 at 8:08

1 Answer 1

0

I have found one solution for the above question.

We can use the FFmpeg command to Normalize the audio in the video. But before that, we need to find out the gain to apply

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

val complexCommand = arrayOf("-i",videoPath,"-af","volumedetect","-f","null","null")

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.

Now we can normalize the .mp4 file using the following FFmpeg command.

val complexCommand = arrayOf(
        "-i",
        originalVideoPath,
        "-af",
        "volume= 5.0dB",
        "-c:v", "copy",
        "-c:a",
        "aac",
        "-strict",
        "experimental",
        "-b:a",
        "128k",
        destinationPath
    )

128k is the audio bit rate of the video that we need to set. It can vary according to the video.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.