An on-demand audio dynamics compressor for PMP and Plex HTPC

The feature described below is only available in Plex Media Player, set to the ‘TV’ / ‘fullscreen’ mode. If you use Plex HTPC, refer additionally to the bottom of this post.

Please understand that Plex Media Player is not an “umbrella term” for all types of Plex clients, but a certain type of Plex client which is available for Windows (x64) and MacOS (and in an older version for the Raspberry Pi2+3).
It will not run on any other device or platform!

This method will not work if you are using ‘Audio Passthrough’ (bitstreaming). Because the point of bitstreaming is of course to not modify the encoded audio stream in any way.
Therefore it will only work if you clear all those ‘Passthrough’ check boxes in the Audio Settings.

What is dynamic range compression?

Very simply put, it will reduce the level peaks of an audio signal. Which then enables you to raise the volume even further without causing the signal to “clip” and thus without getting distortion.

So it can help with the big differences between dialog scenes and action scenes in a movie.
It is applied by TV stations regularly. Which is why many people are already accustomed to it and even expect it.
But it also helps with dialog intelligibility and lets your family and neighbours sleep better during your movie nights :slight_smile:

Building it

You can build yourself such a compressor into PMP by creating a custom input map.
https://support.plex.tv/articles/216459997-create-your-own-inputmap/
My description will use an input map for keyboard control, but you can also do the same with any other input method. You just need to find a button which you can dedicate to toggling the compressor on / off.

Go to the folder which holds the default inputmaps for PMP

  • Windows: C:\Users\USERNAME\AppData\Local\PlexMediaPlayer\inputmaps\examples
  • OS X: ~/Library/Application Support/Plex Media Player/inputmaps/examples
  • Raspberry Pi2/OpenELEC: /storage/.local/share/plexmediaplayer/inputmaps/examples

and copy the file keyboard.json into the parent folder /inputmaps.
Open it in a text editor which can handle Unix line feeds.

Scroll down a bit until you see the section // volume
Underneath the line "\\-": "decrease_volume",
insert a new line with this content:

"Ctrl\\+D": "host:player af toggle lavfi=[acompressor=ratio=4:makeup=2]",

Save the file and you are done.

Now start PMP and play a video.
Then hold CTRL/CMD and tap on D on your keyboard.
This will toggle the compressor on / off.

Closing remarks

  • This method is not recommended to be used with music
  • there is unfortunately no way to make it permanently active
  • there is also no way to activate it as soon as you hit Play
  • you can experiment with the numerical values a bit, but my defaults are a reasonable starting point which balance loudness gain and compression artefacts quite well. For further details, please refer to the ffmpeg documentation FFmpeg Filters Documentation

If you haven’t modified your keyboard.json before, you can just download this already modified version of it. keyboard.zip (1.2 KB)
Unzip it and drop it into the /inputmaps folder described above.


Plex HTPC

For the new PMP-replacement app “Plex HTPC”, the target location of the inputmap file is:

  • Windows C:\Users\<username>\AppData\Local\Plex HTPC\inputmaps
  • macOS: ~/Library/Application Support/Plex HTPC/inputmaps
  • linux: ~/snap/plex-htpc/common/inputmaps

And the hotkey definition needs to be slightly modified to

"Ctrl\\+D": "mpv:af toggle lavfi=[acompressor=ratio=4:makeup=2]",

Everything else works as above (as far as I have tested).


edit history:
2021-03-23 added support for the “Plex HTPC” app

3 Likes

Wow this works great :slightly_smiling_face:

Caveats on a iMac with a wired iMac keyboard,
running PMP-2.40.0.1007

  1. When you press Command on your keyboard, Plex registers Ctrl
  2. When you press Control on your keyboard, Plex registers Meta
  3. Using Otto’s keyboard.json gets you DRC when you press Command+D
  4. You can’t use this with a 6-button AppleRemote. It fires on button down and button up, emitting two toggle commands that have zero sum effect.

Really nice post, thanks again!

1 Like