animeopenings icon indicating copy to clipboard operation
animeopenings copied to clipboard

Apply audio gain to videos

Open AxelTerizaki opened this issue 4 years ago • 2 comments

Hello there.

I have no idea if this is possible or not, but if it could it'd be great.

For Karaoke Mugen we analyze and collect all videos' audio gain values with ffmpeg with the following command line :

ffmpeg -i <file> -vn -af replaygain -f null -

It outputs info about the media file and also calculates its replay gain in decibels.

As we use mpv to play files on the desktop app, it allows us to pass the replay gain as a parameter. It makes for a smoother experience as all videos aren't on the same sound volume, so mpv adjusts the sound volume automatically with the audio gain we collected. (-6 dB, +2.7 dB, etc.)

We were wondering if the same thing was possible with AO's video player, if volume can be adjusted automatically if a audio gain is provided. I'm not even sure if it's possible but who knows ?

AxelTerizaki avatar Sep 30 '19 13:09 AxelTerizaki

This is actually possible, somewhat. It would be something like:

// setup
let context = new AudioContext();
let gain_node = context.createGain();
let source = context.createMediaElementSource(VideoElement);
source.connect(gain_node).connect(context.destination);

// change gain
gain_node.gain.value = gain_value;

The documentation says the default gain value is 1, and you can set it to any number in the range approximately from -3.4 to +3.4, though 0 is muted and negative values are used for phase inversion. It's also a linear gain, not dB gain.

I'm not sure how easy it would be to map that to what you have. We actually just re-encode everything to solve this problem.

Yay295 avatar Oct 02 '19 00:10 Yay295

This is being worked out in !6 merge request. We can merge it back here.

leonekmi avatar Apr 09 '20 13:04 leonekmi