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 :)

No Comments

Leave a Reply

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

* Checkbox GDPR is required


I agree

Officepad – Etherpad alternative based on Onlyoffice

During the Chaos Communication Camp 2019 I was working on a project called Officepad. The aim was to build a web interface comparable to Etherpad. Etherpad is a well established tool for online text collaboration used by software developers, activists and so on. Etherpad is relatively stable and works well …

Bye bye Play Store! Mirroring Play Store Apks to private F-Droid repo

This small tutorial will show you how to setup your own F-Droid repository containing automatically mirrored Play Store apps. Using this private repo, you don’t have to relay on Google Play Store or third party stores anymore to keep non-free apps up-to-date. All you need to have is a Linux …

Ebook reader app for Nextcloud

Because of lack of altenatives I decided to write a small ebook reader plugin for Nextcloud. The task of creating such an app was quite easy: I just forked the files_pdfviewer extension and replaced PDF.js with the Epub.js library. In the app template file, I used the reference ebook reader …