Skip to main content

Hardware Acceleration (GPU)

This section only covers setup for Nvidia GPUs

1. Finding a suitable GPU
2. Installing NVIDIA drivers

Before installing the drivers, make sure, that you meet all requirements:

To start off, make sure, that your /etc/apt/sources.list file includes the contrib and non-free repositories. E.g. the following:

deb http://deb.debian.org/debian/ bullseye main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye main contrib non-free
deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye-updates main contrib non-free

Next, update all packages and install the nvidia-driver package.

apt update
apt -y install nvidia-driver firmware-misc-nonfree

Make sure, that the default nouveau drivers are blacklisted, by running cat /etc/modprobe.d/nvidia-blacklists-nouveau.conf

# You need to run "update-initramfs -u" after editing this file.

# see #580894
blacklist nouveau

If all is set, reboot your machine. You should be able, to verify the loaded drivers now, by running <span class="kw2">lsmod</span> <span class="sy0">|</span> <span class="kw2">grep</span> nvidia:

nvidia_uvm           1273856  0
nvidia_drm             73728  0
drm_kms_helper        278528  1 nvidia_drm
nvidia_modeset       1146880  1 nvidia_drm
nvidia              40828928  2 nvidia_uvm,nvidia_modeset
drm                   618496  4 drm_kms_helper,nvidia,nvidia_drm

Additionally, for monitoring purposes, you can install nvidia-smi. Simply run the following command:

apt -y install nvidia-smi

This allows you, to see your GPU's current status:

~# nvidia-smi
Mon Jul 11 13:33:22 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.48.07    Driver Version: 515.48.07    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:03:00.0 Off |                  N/A |
| 45%   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                                                 |
+-----------------------------------------------------------------------------+
2.1 Installing CUDA Toolkit

This only works on systems with x86\_64 architecture

First, remove outdated signing keys, by running

apt-key del 7fa2af80

After that, setup the CUDA repository:

wget https://developer.download.nvidia.com/compute/cuda/repos/<distro>/<arch>/cuda-keyring_1.0-1_all.deb
dpkg -i cuda-keyring_1.0-1_all.deb

Update your repositories and install CUDA:

apt update
apt -y install cuda

After a successful installation, reboot your system.

2.2 Compiling FFmpeg

Before you start, install the following packages, if missing:

apt -y install build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev pkg-config

After that, clone the ffnvcodec and FFmpeg repository.

git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/

Install ffnvcode:

cd nv-codec-headers && sudo make install && cd ../ffmpeg

Configure FFmpeg:

./configure --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 --disable-static --enable-shared

Compile FFmpeg:

make -j 8 # Change according to available Threads!

Install libraries

make install

Check your installation, by running ffmpeg. If you run into the following error

ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory

you need to make a change to the /etc/ld.so.conf config file. First, find out, where the library is located:

find / -name "libavdevice.so.52"

This returns /usr/local/lib as the location. Simply add this information to the above config file and run

ldconfig

You should now be able to enable Hardware Acceleration in Jellyfin. Head over to your Jellyfin Web GUI and navigate to Administration -> Dashboard -> Playback and set Hardware Acceleration to Nvidia NVENC. Depending on your GPU, you can enable hardware decoding for the supported Codecs. To test, if the GPU is actually doing the work, run a movie, and check nvidia-smi for running processes:

~# nvidia-smi
Mon Jul 11 13:50:25 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 515.48.07    Driver Version: 515.48.07    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:03:00.0 Off |                  N/A |
| 37%   50C    P0    N/A /  N/A |    823MiB /  2048MiB |     66%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A     61181      C   ...ib/jellyfin-ffmpeg/ffmpeg      821MiB |
+-----------------------------------------------------------------------------+