Plex Hardware Transcoding

Intel iGPU HW Transcoding


(Specific instructions and examples below are for a Hetzner dedicated server however much is useful for others as a guide):

For Hetzner server users, the following is how to get the drivers and capability installed on the Linux host.

  • Comment out all line referencing i915 in this file: /etc/modprobe.d/blacklist-hetzner.conf
    • sudo nano /etc/modprobe.d/blacklist-hetzner.conf
    • Add a # in front of the lines “blacklist i915” and “blacklist i915_bdw”
    • # blacklist i915
    • # blacklist i915_bdw
  • Remove Hetzner’s default grub config “nomodeset” which blocks loading of video card drivers:
    • Ubuntu 16 or earlier: nano /etc/default/grub.d/hetzner.cfg or
    • Ubuntu 18.04 or later: nano /etc/default/grub
    • comment out GRUB_CMDLINE_LINUX_DEFAULT=“nomodeset” (it’s okay if it also has consoleblank=0 at the end."
    • # GRUB_CMDLINE_LINUX_DEFAULT="nomodeset consoleblank=0"
  • Update and Reload grub.
    • sudo update-grub
    • For older Ubuntu try sudo grub-mkconfig -o /boot/grub/grub.cfg
  • Add user root (or whoever is the user running the Plex service) to the video group:
    • sudo usermod -a -G video root
  • Reboot the server
  • Try ls -la /dev/dri now it should find the folder and list drivers
  • Type chmod -R 777 /dev/dri to change permissions ( critical step for use in Docker! )
  • I recommend installing and running vainfo and ensure it gives you a positive readout on your driver
    • sudo apt update
    • sudo apt install vainfo
    • vainfo
      • You want a line similar to “vainfo: Driver version: Intel i965 driver for Intel® Haswell Server - 1.7.0” somewhere in the 18-20 lines it puts out.

Note: If VAINFO works, it’s almost a sure bet you’ll be able to get the Docker Plex to work. However, as long as the /dev/dri folder with the two driver files are there, you’re probably okay even if running VAINFO throws an error.


Getting it working (optimally) inside Docker.

The following updates to the Plex Docker container are not strictly necessary - but recommended.

You’ll need to run the following commands from the HOST (to make it easier for you):

  • docker exec plex apt-get -y update
  • docker exec plex apt-get -y install i965-va-driver vainfo
  • docker restart plex

That updates the driver now that it can get to the files outside the container.


Additional tips/tricks:

The following command should give a succinct info read on your iGPU:

GPU=$(lspci | grep VGA | cut -d ":" -f3);RAM=$(cardid=$(lspci | grep VGA |cut -d " " -f1);lspci -v -s $cardid | grep " prefetchable"| cut -d "=" -f2);echo $GPU $RAM

For example, on one of the dedicated servers I use (an Intel Xeon E3-1246V3), the output is: Intel Corporation Xeon E3-1200 v3 Processor Integrated Graphics Controller (rev 06) 256M

However on a non-dedicated VPS I use the output is: Cirrus Logic GD 5446 32M (Yeah…the emulated Cirrus Logic isn’t going to work for hardware encoding.)


Source Information

4 Likes

Nvidia GPU HW Transcoding.


First, on the system host. Install the most recent Nvidia Driver or your preferred version.
Nvidia
***If you have a Card such as a 9XX/10XX/20XX/16XX Series, please refer to these instructions to get the card unlock patch install and setup. Make sure you install the corresponding patch with the drive you installed above.

https://github.com/keylase/nvidia-patch

After that is done you must prepare your system for passthrough to Plex/Emby.

Recommend following his steps for installing the driver and patch so you don’t get overly confused.

Add the package repositories

> distribution=$(. /etc/os-release;echo $ID$VERSION_ID)

curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

 sudo apt-get update

# Install nvidia-docker2 and reload the Docker daemon configuration

sudo apt-get install -y nvidia-docker2

YOU MAY GET THIS MESSAGE :

Configuration file ‘/etc/docker/daemon.json’
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.

What would you like to do about it ? Your options are:
Y or I : install the package maintainer’s version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation The default action is to keep your current version.
*** daemon.json (Y/I/N/O/D/Z) [default=N] ? CHOOSE YES FOR THE NVIDIA RUNTIME TO BE AVAILABLE*

# Restart docker

sudo pkill -SIGHUP dockerd

# Test nvidia-smi with the latest official CUDA image

sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi

After this is complete, you will need to add the following environment variables to your PLEX/EMBY install:

Go to Portainer and click “Duplicate/Edit” on the respective container, then go to the ENV tab and add the information below:

NVIDIA_VISIBLE_DEVICES=all
NVIDIA_DRIVER_CAPABILITIES=compute,video,utility

Lastly go to the runtime & resources area and change to “nvidia”, and redeploy the container.

Any container added after this install with has exposure to nvidia gpu automatically. IF you need the container to actually access the GPU then you must add those environmental variables. I would do a pull request to have them added to the yaml, but I don’t know how to.

Credits for this guide go to justinglock40.

6 Likes

4K HDR HW transcoding Tone mapping issues


Since plex has updated the way they transcode 4K HDR videos (have added tone mapping) plex is unable to HW transcode without some extra steps (you can copy, paste and run this in one step).

sudo docker exec plex bash -c "apt update && apt -y install cmake pkg-config python ocl-icd-dev libegl1-mesa-dev ocl-icd-opencl-dev libdrm-dev libxfixes-dev libxext-dev llvm-7-dev clang-7 libclang-7-dev libtinfo-dev libedit-dev zlib1g-dev build-essential git"
sudo docker exec plex git clone --branch comet-lake https://github.com/rcombs/beignet.git
sudo docker exec plex bash -c "mkdir /beignet/build/ && cd /beignet/build && cmake -DLLVM_INSTALL_DIR=/usr/lib/llvm-7/bin .. && make -j8 && make install"
sudo docker restart plex

you should now be able to HW transcode 4K videos properly :slight_smile:

Credit for this goes to @doobsi and edrock

3 Likes