0

I have a Matroska container with some video stream, some subtitles stream and an AAC audio stream. Now, the audio's gain/volume is too low, relative to other media files I play, and I want to increase the gain - in the file itself, not manually turn up the playing volume. However, I want to avoid recoding the audio. Is there something I can do to increase the gain...

  1. Writing directly into the MKV file, without recreating it (e.g. some kind of meta-data)?
  2. While re-muxing into a new MKV file?
einpoklum
  • 8,783
  • 20
  • 84
  • 153

1 Answers1

2

One possibility is to strip the aac audio out, use aacgain to adjust the gain values in the file (not actual transcoding) and then re-mux it back in.

On Windows it appears there is a possibility in the store with BS FAG which claims to use ffmpeg (probably to copy out the audio stream and mix it back in) and aacgain to do the actual gain job for you. I have not tried this tool and have no affiliation with it.

BS FAG will fix audio gain in video files to proper volume level with clipping sound prevention. Support multiple audio tracks and international file names. Uses FFmpeg (LGPL), mp3gain (Freeware), and aacgain (Freeware).

Mokubai
  • 89,133
  • 25
  • 207
  • 233
  • And you're sure aacgain doesn't recode? – einpoklum May 09 '22 at 12:49
  • I believe it does not reencode. Mp3gain adjusts some "gain" settings within the mp3 frames and from what I know aacgain is the same. It *does* modify the file, but it is not the same as transcoding where you decode the entire audio data and reencode it. Technically the audio data is exactly the same, it is just a "multiplier" on the data output that gets adjusted with the effect of increasing the volume of the output. – Mokubai May 09 '22 at 13:05
  • @einpoklum I've written about mp3gain and how it works [here](https://superuser.com/a/1085616/19943) and I believe aacgain functions in a very similar fashion. *in theory* if you know the gain values applied you should be able to losslessly adjust volume up and back to the original value. **in theory**. At a minimum the aacgain tool website i linked states it is based on mp3gain and functions in the same fashion. "It works by modifying the global_gain fields in the aac samples" – Mokubai May 09 '22 at 13:12
  • Ok... although I'm not sure why all this qualification. You could probably tell it re-encoded, since that takes time. – einpoklum May 09 '22 at 13:31
  • It does not re-encode, the time taken is only that needed to read the file, work out "how loud" it is, then to run through the file data to adjust a few bytes every couple of kilobytes and then re-write the file. The "qualification" is an explanation of the method. There is some processing to work out loudness, but no **real** change to the actual data. Technically the file is not the same, but the changes are largely trivial compared to fully re-encoding the audio data "the hard way". – Mokubai May 09 '22 at 13:59
  • @einpoklum what I have offered is the closest you can likely get without having a player that understands replaygain tags in video files (I don't know of any) and without re-encoding the data again and losing quality. What I have suggested is essentially lossless volume adjustment and avoids any kind of reencoding except from some minor adjustment of file data. `aacgain` operates at a layer above the "hard work" of encoding audio data. – Mokubai May 09 '22 at 14:06