Hacking replay gain audio normalization into Jellyfin

There is already a feature request for audio normalization in Jellyfin media server. This is important if you want to listen to your music collection while always having the same loudness level.

Usually, in different recordings or music genres some tracks are louder and others are more quiet. The standard ReplayGain for audio files tries to normalize audio so everything will have the same loudness for the human ear. The small tool r128gain on Github is able to analyze your whole music collection and also supports different audio formats. It will check the actual loudness or difference to a normal level and will write the values to the file metadata. After installing r128gain, you can run it like this to analyze all audio files in the “music” directory:

r128gain -r music

This command might take some time to scan a bigger music collection.

As said before Jellyfin does not yet support reading or using this metatag. But Jellyfin uses ffmpeg to transcode audio files for lower bitrate streaming and ffmpeg does support Replay Gain. So go to the user settings, navigate to “Playback” and set “Internet quality” to some value other than “Auto”:

Now we’ll have to tweak the Jellyfin source code and append the parameter “-af volume=replaygain=track” to the ffmpeg transcoding options in three appearances in two different files:

return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -af volume=replaygain=track -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at    _zero -segment_time {6} {10} -individual_header_trailer 0 -segment_format {11} -segment_list_entry_prefix {12} -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"",
[...]
var args = string.Format("{0} {1} {2} -map_metadata -1 -map_chapters -1 -threads {3} {4} {5} -af volume=replaygain=track -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero {6} -    hls_time {7} -individual_header_trailer 0 -start_number {8} -hls_list_size {9}{10} -y \"{11}\"",
 return string.Format("{0} {1} -map_metadata -1 -map_chapters -1 -threads {2} {3} {4} {5} -af volume=replaygain=track -f segment -max_delay 5000000 -avoid_negative_ts disabled -start_at_zer    o -segment_time {6} {10} -individual_header_trailer 0{12} -segment_format {11} -segment_list_type m3u8 -segment_start_number {7} -segment_list \"{8}\" -y \"{9}\"",

After modification, recompile and reinstall Jellyfin to your media server. Further you have to restart any running server instance. Now playing any music having the Replay Gain tag will have a normalized volune :)

💬 Are you interested in our work or have some questions? Join us in our public Signal chat pi crew 👋
🪙 If you like our work or want to supprot us, you can donate MobileCoins to our address.

Leave a Reply

Your email address will not be published. Required fields are marked *