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.