Plex Media Player Appliance Using Ubuntu

Posted by Thoughts and Ramblings on Monday, November 4, 2019

Running the embedded version of Plex Media Player requires several compromises when a better experience can be obtained by using a full OS install. So I went through the steps to install PMP on an Ubuntu installation. Not only do I have a powerful playback appliance for Plex but I also have a computer where I can use a browser or any other application where I would want the computer displayed on a TV.

I’m going to assume that the reader is familiar with Linux install, setup, and use so I’m not going into extensive detail in these steps.

  • If you are coming from a previous embedded installation, you should grab autostart.sh, plexmediaplayer.conf, mpv.conf, and inputmaps

    • It is easiest if you turn on SMB sharing and access the shares. The autostart.sh is in the Configfiles share and the others are in the PMPConfig share
  • Install Ubuntu

    • It is much more convenient to set it to auto-login when you create the user so you don’t have to type in the password when you reboot the device
  • Reboot after install completes (it should ask you to do this)

  • Open System Preferences (power icon in upper right -> tools looking icon in lower left of menu)

    • In Power change Blank screen to Never to disable the auto-lock
    • Change the desktop background (the default background is such high saturation that it produces a noticeable afterimage on your retina after looking away)
    • In Notifications turn off the two types of notifications
    • In Privacy edit the problem reporting and turn it off. It should then say Never when complete. This disables the dialog displaying over the video.
  • Disable the update notification dialog (so it doesn’t show up in the middle of your playback)

    • In terminal, execute cd ~/.config/autostart
    • cp /etc/xdg/autostart/update-notifier.desktop .
    • Edit that file update-notifier.desktop and add a line Hidden=true to the end
  • Run software update (likely need another reboot)

  • This is an opportune point to configure Bluetooth devices and WiFi should you use them

  • Mostly follow these instructions: https://github.com/plexinc/plex-media-player#building-on-linux

    • In the first, with the list of things to install, add python to the list
    • You may use the OS provided Qt or install it from the installer
      • When you download the Qt installer, you must make it executable before you can open it. Ctrl-I will show a dialog and in the Permissions, check the box to make it executable
      • When installing QT, select version 5.12.3 (you can unselect the android versions)
    • When doing the building mpv steps, execute ./use-mpv-release && ./use-ffmpeg-release before the rebuild step to use the a release version over development
    • When building PMP itself, the -DQTROOT will be -DQTROOT=/home/username/Qt/5.12.3/gcc_64/ (substitute in your username)
  • If your are coming from a previous installation, create the dir ~/.local/share/plexmediaplayer and put the plex config files in there

  • In the PMP checkout, copy the resources/desktop/plexmediaplayer.desktop to the desktop

    • Change the exec line to read Exec=env QT_XCB_GL_INTEGRATION=xcb_egl plexmediaplayer

    • Execute this shortcut because it must be run once to become trusted. You’ll need to make it executable first just like above

  • Create a bin directory in your home dir and in it create the file setupAndLaunchPMP.sh with the contents:

#!/bin/sh

# Put any previous setup commands you had in here such as came from your old autostart.sh file

sleep 2

QT_XCB_GL_INTEGRATION=xcb_egl plexmediaplayer
  • Make sure the file is executable
  • Go into the startup applications
    • Make a login item to execute the above script on login

Updating

  • Updating Ubuntu itself can be done by launching the Software Updater application
  • PMP can be updated by:
    • Opening the terminal and change directory into the PMP source you grab earlier
    • git pull
    • cd build
    • `make -j4`
    • sudo make install
    • Then restart PMP and you are updated

Switch to ALSA Audio

Ubuntu comes with PulseAudio configured but PulseAudio doesn’t support matching the channel count of the output with the source audio. So if you configure it to output 7.1 and you play content that’s in stereo, it will up-convert your stereo content to 7.1 and, to my ears, definitively do it incorrectly. I’d much rather have my AVR get stereo and it do the pro-logic decode or whatever processing I have configured on it.

  • Disable pulse audio (Ubuntu 18.04)
    • cp /etc/pulse/client.conf ~/.config/pulse
    • Edit ~/.config/pulse/client.conf
    • Change the line ; autospawn = yes to autospawn = no
    • Change the line ; daemon-binary = /usr/bin/pulseaudio to daemon-binary = /bin/true
  • Disable pulse audio (Ubuntu 20.04 since the above no longer works)
    • systemctl --user mask pulseaudio.socket
    • systemctl --user mask pulseaudio.service
  • In PMP’s settings:
    • In Audio, disable all the codecs for audio passthrough
    • In Audio, set the output device. Mine was HDA Intel PCH, HDMI 0/HDMI Audio Output (the first HDMI one)
    • Set Audio -> Channels to Auto Select Channels
    • In Video -> Sync Mode, set this to Display (resample audio)
  • Reboot to ensure all the steps are working
    • Run a ps ax | grep pulse and ensure that the only line you get (if any) is the grep command

Using Passthrough

I attempted to use passthrough repeatedly on my NUC8 but no matter what I tried it would not passthrough any HD-audio codecs (TrueHD/DTS-HD) but it had no issue with AC3, EAC3, and DTS. My NUC4 has no issues with any of the codecs so, including the HD-audio ones, go figure. This issue appears to be exclusively an issue with the receiver not being HDMI 2.0. Upon upgrading to an HDMI 2.0 receiver, the HD-audio codec passthrough worked on the NUC8. Perhaps an Intel bug to do the passthrough in a means that an HDMI 1.4 device didn’t understand.

  • First follow above settings to use ALSA
  • In PMP’s settings:
    • In Audio, ensure you have the passthrough codecs selected in audio
    • In Video -> Sync Mode, set this to Audio
      • I have tried fiddling with the video-sync=display-vdrop setting here and it appears to work better than audio but this requires modification to PMP’s source code.

Customization

mpv.conf

Modifications to the mpv.conf file allow a great amount of control to how the playback performs. Most notably if the hardware is capable enough, it can greatly enhance the quality of video scaling and playback in general. There are a great many posts on this topic (such as this one) but at the moment I am using the following:

video-output-levels=limited

demuxer-mkv-subtitle-preroll

profile=gpu-hq
deband=yes

# interpolation=yes
# tscale=oversample

scale=ewa_lanczossharp

audio-stream-silence=yes

Explanations

  • video-output-levels=limited: I have my TV configured to accept the limited color space. Similarly I’ve configured the graphics card to output full. See this forum post for more details. I have a xrandr --output DP-1 --set "Broadcast RGB" "Full" in my setupAndLaunchPMP.sh file
  • demuxer-mkv-subtitle-preroll Appears to show subtitles immediately after a seek instead of waiting for the next set of subtitles before display.
  • profile=gpu-hq An easy profile to gain a lot of playback enhancements.
  • deband=yes Reduce any visible banding artifacts
  • interpolation=yes Provides from interpolation for cases where the display framerate cannot be matched to the source. I have since disabled this because it can rarely cause frames to be displayed out of order. Since I match framerates almost every time, I rarely need any frame interpolation and the disadvantage outweighs the advantage for me.
  • tscale=oversample Configuration for the interpolation to use a simple mechanism. This does not do motion enhancement or the so-called “soap opera effect.” I have also disabled this; see above.
  • scale=ewa_lanczossharp Overrides the scaler used in the gpu-hq profile with one that yields better quality
  • audio-stream-silence=yes Plays silence while the video is paused. This appears to resolve a small audio drop I experience sometimes after I resume from pause

plexmediaplayer.conf

Almost all of these are accessible in the UI but a few are not. Among the latter, ones I have changed are:

  • Video
    • audio_delay.24hz, audio_delay.25hz, audio_delay.50hz, audio_delay.normal to set audio delay at various refresh rates to ensure A/V sync in playback.
    • refreshrate.avoid_25hz_30hz I set the to false because the 29.97Hz refresh rate appears to yield the best playback experience for a DVD remux.
    • refreshrate.delay I’ve set this because my TV takes a few second between a refresh rate change and display of the video

Inputmaps

You can copy the example input map to the inputmaps dir and modify it to change the actions taken on a keypress. This is going to be very user specific but essentially I’ve set keymaps to do:

  • cycle_subtitles
  • cycle_audio
  • host:cycle_setting video.aspect

The actions these take should be fairly self explanatory.

Conclusion

That’s it. I feel this technique of running a full OS instead of the embedded LibreELEC OS provides a better experience to the end user in the long run. It’s significantly easier to setup BlueTooth devices in Ubuntu than it is in LibreELEC as well as any other hardware setup I might wast to do.

Hopefully you have find this guide useful and enjoy your playback setup.

Edits

  • 2019-12-02: Added disabling the problem reporting dialog
  • 2020-01-21: Disabled interpolation due to frame ordering issue
  • 2020-01-26: Added information about passthrough working when receiver is HDMI 2.0 compatible
  • 2020-10-28: Added info on how to disable pulseaudio in Ubuntu 20.04
  • 2020-11-16: Added QT_XCB_GL_INTEGRATION=xcb_egl environment variable since it allows for better hardware decoding