I have a script to process/encode videos. Some of the videos have varying audio levels (like 2 videos were merged and one had loud audio and other quiet audio). I want to normalize the audio in a way that loud audio is reduced and quiet audio is increased to make them both almost equal. Although I am using HandbrakeCLI for encoding but any other solution like ffmpeg which can be used from Linux terminal will work.
I have done some R&D but I have very limited knowledge about audio so I could not make it work. Some of the solutions I have been looking into are audio-normalize and Replaygain (Just a tag but I need to directly change the video when encoding not just add a tag).
I have a sample input and a sample output. Sample output is created by manually selecting loud audio and decreasing it and manually selecting quiet audio and increasing it.
As you can see in the original audio, whole audio is quiet except last small part which is too loud and in the output both are almost equal. But the problem is I want to do it automatically.