4

I came across this answer

How can I normalize audio using ffmpeg?

However this involves transcoding the audio stream. I know that programs like

can adjust the volume losslessly, that is to say without transcoding the file. Can FFmpeg do this?

slhck
  • 228,104
Zombo
  • 1

1 Answers1

5

Lossless Gain?

No, ffmpeg cannot apply lossless audio gain methods like ReplayGain. You have to convert the audio, and if you want it to stay lossless, you have to output to a lossless file (e.g. PCM WAV, FLAC, …).

That said, ffmpeg at least supports reading the ReplayGain data.

Using ReplayGain while encoding

ffmpeg supports ReplayGain in the volume filter. If you read a file with ReplayGain metadata and convert it, you can use the ReplayGain side data to adjust the volume:

ffmpeg -i input.mp3 -af volume=replaygain=track output.wav

Here, the track volume is used. There is also album. Note that the default is to ignore ReplayGain.


Reading ReplayGain data

If you want to read out ReplayGain data, you can just use the replaygain filter:

ffmpeg -i input.mp3 -af replaygain -f null /dev/null

Example output:

Input #0, mp3, from 'apev2-track-only.mp3':
  Metadata:
    encoder         : Lavf57.56.100
  Duration: 00:00:08.93, start: 0.025057, bitrate: 151 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 151 kb/s
    Metadata:
      encoder         : Lavc57.64
Stream mapping:
  Stream #0:0 -> #0:0 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
  Metadata:
    encoder         : Lavf60.16.100
  Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc60.31.102 pcm_s16le
[Parsed_replaygain_0 @ 0x6000029e0d10] track_gain = +13.69 dB
[Parsed_replaygain_0 @ 0x6000029e0d10] track_peak = 0.084451
slhck
  • 228,104
  • by looking at ffmpeg filters documentation(https://ffmpeg.org/ffmpeg-filters.html#replaygain) i can see : replaygain_preamp flag . is that might be replaygain normalization with ffmpeg ? – user39294 Jun 30 '15 at 05:48
  • Is this still true? http://trac.ffmpeg.org/ticket/2699#comment:12 – Zombo Feb 23 '18 at 01:35
  • @StevenPenny From what I understand, FFmpeg can only read ReplayGain info and apply it while using the volume filter, but not actually calculate it or write it as a metadata value. – slhck Feb 23 '18 at 08:19
  • @slhck Can ffmpeg v6 calculate and write ReplayGain metadata by now ? – SebMa Mar 07 '24 at 15:46
  • 1
    @SebMa No, it can only parse and use it for volume adjustments, not actually calcualte it. I did update the answer though since at the time I wrote it, parsing was not supported. – slhck Mar 08 '24 at 08:58