Plex HTPC audio settings reset every update

In an effort to try to work around Plex’s behavior, I started to look into whether the mpv configuration could be overridden with a lua script. Here is what I’ve put together so far, but have never done this before and have only very minimally tested it. It is entirely possible it doesn’t do all of the setup needed to override whatever Plex tells mpv to use for the audio configuration (particularly if it has been fully reset), but it might be a helpful start for people to experiment with:

-- force Plex's mpv to use specific audio device settings
--  this is particularly useful if the WASAPI device endpoint name keeps
--  changing, which causes Plex to appear to reset all of the audio device
--  settings, since Plex does not provide a way to use the plain text
--  description to select the audio device

mp.observe_property("audio-device", "string", function(ad, plexaudiodev)
    local myaudiodev = "wasapi/AUDIO-DEVICE-DESCRIPTION-HERE"
    if plexaudiodev ~= myaudiodev then
        mp.set_property("audio-device",     myaudiodev)
        mp.set_property("audio-channels",   "2.0,2.1,3.1,5.1,7.1")
        mp.set_property("audio-spdif",      "ac3,eac3,truehd,dts,dts-hd")
        mp.set_property("audio-exclusive",  "yes")
    end
  end)

Just save this as force-audio-device.lua in the AppData\Local\Plex HTPC\scripts directory and replace AUDIO-DEVICE-DESCRIPTION-HERE with the description of the Audio Device you want to use (note that it still needs the wasapi/ prefix). If anyone has any input on other mpv options/settings that need to be configured for doing this, I’d be happy to add them!

Thanks, @alphafoxtrot! This is amazing! How has it been working for you since you wrote this?

So is this the fix? @gbooker02 are there plans Plex to officially address the problem? Or should we use script from @alphafoxtrot to keep things stable after driver updates?

Unfortunately, I got swamped with work stuff shortly after I put the script together and haven’t had time to really do much with it. In addition, it isn’t that easy for me to tinker with it on my HPTC setup and I can only go so far with my desktop system, so I’m hoping someone with a little bit more accessible setup can help me test it out.

That said, I think this version of the script has a structural bug. Basically, the way it works is the observe_property call sets up an event listener that triggers the function to be called whenever the audio-device value changes. Then, the function checks if it is different than the desired description and, if so, it is intended to overwrite the whole audio configuration used by mpv regardless of what Plex tells mpv to use. That is generally what we’re trying to accomplish with this workaround.

However, in looking at the log files, I think it fires “too early”. Plex sets the audio-device and then sets a few of the other audio parameters. I think what likely ends up happening is that the audio-device gets changed properly by the script, but I think at least some of the other audio parameters get set by the script and then are overwritten when Plex sets them itself. It’s just a timing/sequencing issue; I don’t think it’s fatal to the general approach.

The solution is relatively straight forward: it just needs an observe_property call for each of the audio parameters separately and then have the corresponding function overwrite the value when Plex sets it to something different than what we want.

I could probably whip up an updated script fairly quickly, but I was actually hoping that @gbooker02 would chime in on a couple of things before I did so:

First, I’d appreciate a response to the point I raised before about frequent GPU driver updates, that:

As I linked above, mpv actually supports taking the description as the audio device.

Second, at a minimum, I’d appreciate confirmation of what all of the mpv audio parameters set by Plex are and what the proper values are for full HDMI passthrough of all audio formats. I went off of what I saw in the logs, but wasn’t sure I was setting things to be equivalent to our desired Plex settings in the format required by mpv.

I threw together a revised script that addresses the problems I noted before. If I’m reading the log files correctly, it does seem to do the right thing, but I am still unclear whether it captures all the settings that need to be overwritten as between a “default” Plex audio configuration and one fully set up for a specific audio device.

If someone could help test it out, it would be greatly appreciated (it seemed to work as far as I was able to test on my desktop system):

-- force Plex's mpv to use specific audio device settings
--  this is particularly useful if the WASAPI device endpoint name keeps
--  changing, which causes Plex to appear to reset all of the audio device
--  settings, since Plex does not provide a way to use the plain text
--  description to select the audio device
local myaudiodev        = "wasapi/AUDIO-DEVICE-DESCRIPTION-HERE"
local myaudiochannels   = "2.0,2.1,3.1,5.1,7.1"
local myaudioformats    = "ac3,eac3,truehd,dts,dts-hd"
local myaudioexclusive  = "yes"

mp.observe_property("audio-device", "string", function(propname, plexaudiodev)
    if plexaudiodev ~= myaudiodev then
        mp.set_property("audio-device", myaudiodev)
    end
end)

mp.observe_property("audio-channels", "string", function(propname, plexaudiochannels)
    if plexaudiochannels ~= myaudiochannels then
        mp.set_property("audio-channels", myaudiochannels)
    end
end)

mp.observe_property("audio-spdif", "string", function(propname, plexaudioformats)
    if plexaudioformats ~= myaudioformats then
        mp.set_property("audio-spdif", myaudioformats)
    end
end)

mp.observe_property("audio-exclusive", "string", function(propname, plexaudioexclusive)
    if plexaudioexclusive ~= myaudioexclusive then
        mp.set_property("audio-exclusive", myaudioexclusive)
    end
end)

As before, just save this as force-audio-device.lua in the AppData\Local\Plex HTPC\scripts directory and replace AUDIO-DEVICE-DESCRIPTION-HERE with the description of the Audio Device you want to use (note that it still needs the wasapi/ prefix). You can find the exact language for the Audio Device description if you open up the Plex HTPC.log file and search for audioDeviceList.

@gbooker02 The culprit is NVIDIA driver updates on Windows. I just did some testing and found that absolutely every time I update or downgrade (through the NVIDIA GeForce Experience or otherwise), it resets the audio settings going through the HDMI port. Given that this silently fails yet is still reported often on Reddit, my guess is that this problem is pretty widespread.

I urge you to try it yourself, or find a colleague with an NVIDIA card. Reproducing is as simple as updating the NVIDIA driver on Windows.

I was afraid we had reached the point of agreeing-to-disagree, but I just noticed the changelog for a recent version:

Specifically:
Use audio device description in addition to name when selecting preferred audio device

So hopefully that does what it sounds like and things are fixed! @gbooker02 or @Moussa, can you confirm?

I believe that should fix the issue discussed here, but interested to get feedback.

1 Like

My Plex HTPC just updated last night, so that’s what made me look at the change log. I will definitely keep an eye out for any issues going forward. But in anticipation of everything working smoothly, thank you all very much!

Wow, thanks for addressing this Plex team! I’m away from home for a few days but will check this out when I get back. Seems to need an NVIDIA driver update to trigger the reset, so it might be a bit longer if there isn’t also an update pending on that front as well.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.