FFmpeg is a free and open-source video editing tool capable of trimming, cropping, concatenating, muxing, and transcoding almost any type of media file you throw at it.
It's also a very robust solution for implementing video automation, as we use it extensively in our own video editing API. For this tutorial we'll use FFmpeg 5.1.2, but any recent version will do.
As we are only changing the audio track, we do not need to re-encode the video. Here's how:
$ ffmpeg -i input.mp4 -af "volume=0.5" -c:v copy output.mp4
Changing the volume of an audio file is as easy as this:
$ ffmpeg -i input.mp3 -af "volume=0.5" output.mp3
With volumedetect, we can find out how much a track's volume can be increased:
$ ffmpeg -i input.mp3 -af "volumedetect" -vn -sn -dn -f null -
The -vn -sn -dn arguments specify that all non-audio streams can be ignored. By using -f null -, FFmpeg won't output to a file, but instead prints out the results:
1$ ffmpeg -i input.mp3 -af "volumedetect" -vn -sn -dn -f null -
2
3...
4[Parsed_volumedetect_0 @ 000002460e7c7600] n_samples: 1414656
5[Parsed_volumedetect_0 @ 000002460e7c7600] mean_volume: -20.9 dB
6[Parsed_volumedetect_0 @ 000002460e7c7600] max_volume: -5.3 dB
7[Parsed_volumedetect_0 @ 000002460e7c7600] histogram_5db: 34
8[Parsed_volumedetect_0 @ 000002460e7c7600] histogram_6db: 495
9[Parsed_volumedetect_0 @ 000002460e7c7600] histogram_7db: 1479
10
The most interesting lines have been highlighted above. According to FFmpeg, the audio's max_volume is about -5.3 dB, so we can safely increase the volume to 5 decibels before any significant audio clipping occurs. The histogram_ values give us an idea of how many samples are being clipped as decibels increase. For a volume increase of 5 dB, this would be 34. However, we shouldn't bump the volume by 7 dB as that will clip 1479 samples.
After we have decided by how many decibels we want to increase the audio, we can apply the volume gain using the commands mentioned above. Therefore, in this case, I'd use -af "volume=5.3dB" to boost the volume by 5.3 decibels.