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

Software
Importing playlists to Jellyfin media server

In the following post I would like to describe a way to import music playlists to Jellyfin media server, for example in case you want to migrate them from a former Plex or Emby installation. Usually, Jellyfin is already able to detect playlist files within the media library. Unfortunately my …

Software
Jellyfin media server on Archlinux ARM

In this post, I want to share some insights on building Jellyfin media server for Archlinux ARM. The PKGBUILD for Jellyfin one can find on the AUR, is specifically made for 64 bit architectures. Nevertheless Microsoft released the dotnet runtime, which Jellyfin relies on instead of Mono, also for Linux …

Software
2
Voice control Archlinux with Amazon Alexa

I was interested to see how commercial voice recognition software would behave on an usual Linux laptop and tried to deploy an Amazon Alexa instance. There are some installation scripts and tutorials available for Ubuntu and Raspberry PI using the avs-device-sdk from Github. Even though some of them are official …