Hardware Transcoding support in docker container isnt working

Hi all,

I have the following setup and try to enable hw encoding.

**System: Lenovo P330 Tiny with 8G RAM + i5-8500, Quadro P400 and 256GB **
OS: Fresh installation of Ubuntu 22.04.1 LTS
GPU Driver: Ubuntu proposed the installation of the nvidia-515.65.01 driver which I checked

After clean installation and a full apt update / upgrade run followed by fwupdmgr, I installed docker engine and docker compose. nvidia-smi looks good for me on the host system.

root@pve2:/home/numark1# nvidia-smi
Fri Aug 12 12:21:17 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| 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 P400**         Off  | 00000000:01:00.0 Off |                  N/A |
| 54%   51C    P0    N/A /  N/A |      0MiB /  2048MiB |      2%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

After that I installed the nvidia-toolkit and veryfied it with the nvidia dummy container:

root@pve2:/home/numark1# docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
Unable to find image 'nvidia/cuda:11.0.3-base-ubuntu20.04' locally
11.0.3-base-ubuntu20.04: Pulling from nvidia/cuda
d7bfe07ed847: Pull complete
75eccf561042: Pull complete
191419884744: Pull complete
a17a942db7e1: Pull complete
16156c70987f: Pull complete
Digest: sha256:57455121f3393b7ed9e5a0bc2b046f57ee7187ea9ec562a7d17bf8c97174040d
Status: Downloaded newer image for nvidia/cuda:11.0.3-base-ubuntu20.04
Fri Aug 12 13:06:07 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.65.01    Driver Version: 515.65.01    CUDA Version: 11.7     |
|-------------------------------+----------------------+----------------------+
| 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 P400         Off  | 00000000:01:00.0 Off |                  N/A |
| 47%   49C    P0    N/A /  N/A |      0MiB /  2048MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

I thenk installed the linuxserver.io container, enabled nvidia runtime and set up the env variables for thge hardware.

version: "3.9"
services:
  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    network_mode: host
    runtime: nvidia
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - PLEX_CLAIM=claim-XYZ
      - NVIDIA_VISIBLE_DEVICES=GPU-00000000-aaaa-bbbb-cccc-000000000000
    volumes:
      - /home/numark1/docker/data_plex/config:/config
      - /home/numark1/docker/data_plex/tv:/tv
      - /home/numark1/docker/data_plex/movies:/movies
    restart: unless-stopped

Additionally I executed nvidia-smi inside the container which was sucessfull.

I have a Plex Pass Lifetime and the hw transcode option is enabled in the plex settings.

Whenever something needs transcoding CPU usage spikes to 90% and the stream is stuttering, this hardware setup was running before without the docker part. At the moment I dont know what I missed or what can check ?

BR Daniel

Server Version#:
Player Version#:

Is the Plex user a member of the group which owns /dev/dri ?
(This is a common oversight)

FWIW:

  1. PMS looks for the renderD128 node.
  2. With the Nvidia drivers installed, the P2200 is visible in /dev/dri
  3. I grant device-level access in the container:
sudo docker stop plex
sudo docker rm plex

# Remove old image if exists
Image="$(sudo docker images | grep -i plex | awk '{print $3}')"

if [ "$Image" != "" ]; then

  sudo docker stop plex
  sudo docker stop plex
  sudo docker rm plex
  sudo docker rmi -f $Image
fi


sudo docker run \
-d \
--name plex \
--network=host \
-e TZ="EST" \
-e LANG="en_US.UTF-8" \
-e PLEX_UID=1000 \
-e PLEX_GID=1000 \
-e PUID=1000 \
-e PGID=1000 \
-h dockerplex \
-v /sata/dockerplex:/config \
-v /sata/dockerplex/tmp:/tmp \
-v /sata/dockerplex/transcode:/transcode \
-v /vie:/data \
--device=/dev/dri:/dev/dri \
plexinc/pms-docker:plexpass

#docker start plex
#docker update --restart=unless-stopped plex
1 Like

So I added the user plex is running (ID=1000) to the root group but that didnt changed something.

Regarding the device assignment, I was pretty sure that the /dev/dri is only used with integrated graphics and if you have the nvidia-toolkit installed they expose everything via the nvidia runtime into the container so you dont have to add the device variable into your compose file. But I tried it also with the following setup:

version: "3.9"
services:
  plex:
    image: lscr.io/linuxserver/plex:latest
    container_name: plex
    network_mode: host
    runtime: nvidia
    environment:
      - PUID=1000
      - PGID=1000
      - VERSION=docker
      - NVIDIA_VISIBLE_DEVICES=all
    volumes:
      - /home/numark1/docker/data_plex/config:/config
      - /home/numark1/docker/data_plex/series:/tv
      - /home/numark1/docker/data_plex/movies:/movies
    devices:
      - /dev/dri:/dev/dri
    restart: unless-stopped

But this also didnt worked, a bit frustrating. Do you know for what I can search in the logs what need to be triggered or what I need to have a look on ?

I had a look at the logs and found the following lines which tell me that nvenc is report that the different codes arent available for transcoding.

Aug 13, 2022 10:53:28.154 [0x7f9360470b38] DEBUG - [Req#13c/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:28.154 [0x7f9360470b38] DEBUG - [Req#13c/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:28.456 [0x7f9360470b38] ERROR - [Req#13c/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:28.456 [0x7f9360470b38] WARN - [Req#13c/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:28.540 [0x7f9360470b38] DEBUG - [Req#13c/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:28.540 [0x7f9360470b38] DEBUG - [Req#13c/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:28.581 [0x7f9360470b38] ERROR - [Req#13c/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:28.581 [0x7f9360470b38] WARN - [Req#13c/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:48.550 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:48.550 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:48.623 [0x7f9366e25b38] ERROR - [Req#230/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:48.623 [0x7f9366e25b38] WARN - [Req#230/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:48.754 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:48.754 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:48.803 [0x7f9366e25b38] ERROR - [Req#230/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:48.803 [0x7f9366e25b38] WARN - [Req#230/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:48.897 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:48.897 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:48.959 [0x7f9366e25b38] ERROR - [Req#230/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:48.959 [0x7f9366e25b38] WARN - [Req#230/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:49.068 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:49.069 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:49.135 [0x7f9366e25b38] ERROR - [Req#230/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:49.135 [0x7f9366e25b38] WARN - [Req#230/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:49.254 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:49.254 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:49.300 [0x7f9366e25b38] ERROR - [Req#230/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:49.300 [0x7f9366e25b38] WARN - [Req#230/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'
Aug 13, 2022 10:53:49.396 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: testing h264_nvenc (encoder)
Aug 13, 2022 10:53:49.396 [0x7f9366e25b38] DEBUG - [Req#230/Transcode] Codecs: hardware transcoding: testing API nvenc
Aug 13, 2022 10:53:49.462 [0x7f9366e25b38] ERROR - [Req#230/Transcode] [FFMPEG] - The minimum required Nvidia driver for nvenc is 418.30 or newer
Aug 13, 2022 10:53:49.462 [0x7f9366e25b38] WARN - [Req#230/Transcode] Codecs: avcodec_open2 returned -1 for encoder 'h264_nvenc'

This looks like the same error mentioned here: running ffmpeg with nvenc inside nvidia docker - Stack Overflow and my assumption is that not all codecs are available inside the container.

I added the following lines to the env variables and remove the image to have a image from scratch but its still not working.

  - NVIDIA_VISIBLE_DEVICES=all
  - NVIDIA_DRIVER_CAPABILITIES=all

What a ride, finally it is working.

So the next problem was that after reading some rumors about the fact that the nvidia-driver-515-server is not exposing all the necessary codes into the container, I tried to update the driver to the plain nvidia-driver-515 which ended up in a boot loop and “out-of-memory” grub error. Looks like a known issue with nvidia driver and 22.04 because the module dependencies creating a too big initramfs which cannot be loaded by grub. I solved that problem with a config change in the /etc/initramfs-tools/initramfs.conf changing modules to “dep” and compression to bzip2.

With the nvidia-driver-515 everything works as expected, you dont even have to mention the /dev/dri device or add the user to the group.

Because of documentation purposes I also created a blogpost about the whole installation process here Running Plex in Docker with hw transcoding - digital-creations (digcre.io)

1 Like

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