Plex transcoding with Docker – NVIDIA GPU

Plex

Introduction

To use Plex transcoding with Docker we need to passtrough the NVIDIA GPU to the Docker container. Plex has the ability to fully use the NVIDIA GPU for video transcoding like a bare metal install. In this post I will explain the needed steps to get Plex transcoding to work. In this example we will use Ubuntu 22.04

Update (02-09-2024) – driver version 550

Updates the post with the latest NVIDIA container install commands and drivers version 550. Let me know if everything still works okay in the comments!

Bol AlgemeenBol Algemeen

NVIDIA drivers server

First we need to install the NVIDIA driver. On Ubuntu or Debian based systems we can install the drivers from apt. As this is a server without a GUI we will go for the headless drivers. After installing the NVIDIA driver we also need to install the package libnvidia-encode for the video transcoding.

# Search apt for NVIDIA drivers.
sudo apt search nvidia-driver
# At the time of writing the latest driver is 550.

# Install the headless server drivers.
sudo apt install nvidia-headless-550-server

# Install the NVIDIA Utils
sudo apt install nvidia-utils-550-server

# Search apt for libnvidia-encode. Needed for Plex transcoding
sudo apt search nvidia-encode

# Install the libnvidia-encode package.
sudo apt install libnvidia-encode-550-server

After installing all the packages reboot your server and check if everything works correctly with the nvidia-smi command.

nvidia-smi

# Output
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.73.05    Driver Version: 510.73.05    CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Quadro P2000        Off  | 00000000:0B:00.0 Off |                  N/A |
| 44%   31C    P8     5W /  75W |      2MiB /  5120MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

NVIDIA container toolkit

After installing the drivers we need to install the NVIDIA container toolkit. More information about the NVIDIA container toolkit can be found on the NVIDIA docs site.

Setting up the package repository

# Add the gpgpkey and repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg   && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |     sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' |     sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

Installing the NVIDIA container toolkit

# Update and install NVIDIA Container Toolkit
sudo apt-get update

sudo apt-get install -y nvidia-container-toolkit

# Configure NVIDIA Container Toolkit
sudo nvidia-ctk runtime configure --runtime=docker

sudo systemctl restart docker

# Test GPU integration
docker run --gpus all nvidia/cuda:11.5.2-base-ubuntu20.04 nvidia-smi

Docker compose options

After all the local packages we need to configure our Docker compose file to use the NVIDIA GPU inside the Plex container. I will assume you have the latest version of Docker installed with the new Docker compose version. Below is an example of my Docker compose file for Plex transcoding with Docker.

Important

When using this guide you need the use the LinuxServer.io Plex Docker image. The official image is missing NVIDIA packages that prevent transcoding from working correctly.

---
version: "3.8"
services:
  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    network_mode: host
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

    environment:
      - PUID=1001
      - PGID=1001
      - VERSION=docker
      - PLEX_CLAIM=##CLAIM-TOKEN##
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
    volumes:
      - /home/tizu/plex/appdata/config:/config
      - /mnt/media/TV Shows:/tv
      - /mnt/media/Movies:/movies
      - /mnt/media/Music:/music
    restart: unless-stopped

Next spin up the Docker stack and test the transcoding. In Plex you need to make sure it says Transcode (hw) when transcoding a video. For example:

Transcode (hw)

Conclusion

It took me quite a while to get this setup working correctly. The most important thing I was missing was the libnvidia-encode package. For another example with Ollama head over to my NVIDIA GPU with Docker post I hope this post helps you out getting the NVIDIA transcoding working in Plex. If you have any questions leave them in the comments!

If you are looking for a great deal for a graphics card. Click the link below!

Graphic Cards

17 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Wanted to give some people a hand here. There is a need to “crack” the install to unlock the GPU. The official drivers cap your number of transcodes. This website has a patch that would allow for you to unlock it. The 550 version I had wouldn’t work, but the 565 version does:

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

    I have to do this anytime I install a new driver and it works quick.

  2. Do I need to add a certain repository to be able to even find the 550-server driver?
    “sudo apt search nvidia-driver” do not show any server/headless 🙁

  3. First of all
    Thank you. It’s an excellent manual that helps a lot!

    I admit I’m doing things a little differently, but maybe it’ll help other users like me.
    My setup is:
    – Windows machine running WSL
    – ContainerD instead of docker
    – Kubernetes on top of everything

    I’ve installed the Nvidia drivers and Cuda solution on my host and enabled the containerd configuration.

    The solution seems to be promising as when I run nvidia-smi on the host and inside the plex container.
    I get the desired output.

    In addition, I wrote a docker image based on Python and TensorFlow to validate that Cuda can see the GPU device (and it can)

    But, when I go to the Plex server UI -> Settings -> Transcoder
    In the Hardware transcoding device, I only see the AUTO device
    Without the GPU being listed. Needless to say, I have Plex Pass

    Anyway I’m kind of lost, and maybe you know what I’m missing 🙂

    BTW if you’d like to write a post about setting up a setup like mine, I’d be happy to assist,
    I’ve documented it all

  4. Yeah I needed to specify more detail in the compose file to get it up and running.

    deploy:
    resources:
    reservations:
    devices:
    – driver: nvidia
    count: 1
    capabilities: [gpu]

  5. For anyone else scratching their head, not running docker compose, but instead docker run (following the official plex docker guide), add the –gpus all flag at the end of the run command (as shown in the cuda test).

  6. Tried this the other night and it didn’t work for me got nvidia-smi output and the test cuda image did what it was support to do with nvidia-smi output but my plex docker will not spin up when enabling the gpu option.

    Any suggestions on how to troubleshoot this issue “Cannot read properties of null (reading ‘push’)” in portainer after adding env and turning on GPU

      • I was able to get my graphics card to work in Plex, deployed via a Portainer Stack, using your instructions. Nvidia driver 550, Ubuntu 22.04.5. At first, I could not get the card to show up in the Plex container, but then I removed the Version declaration at the top of the Stack. Once I did that, the gpu appeared in Plex. I also used NVIDIA_DRIVER_CAPABILITIES=all; not sure if that was a factor. Thank you very much for this guide. It was extremely helpful.

  7. Thanks so much for this! I finally got this working after trying a bunch of times over the course of a year. Now, to see if this actually helps concurrent streams transcoding…

  8. I’ve followed a few too many guides, but this one worked for me. Appreciate the detailed write up, this was quick and got hw transcodes working!

  9. Hi! I followed the tutorial and everything worked well until i can’t see the “Transcode (hw)” part.
    nvidia-smi shows my NVIDIA GPU without no problem.

    I entered in PLEX support webpage and says that function can only be enabled with plex-pass.

  10. Hello,

    I am attempting to install the drivers, also on Ubuntu 22.04.
    I don’t see any “headless” offerings in the search results.