Home Jellyfin Hardware Acceleration on Docker
Post
Cancel

Jellyfin Hardware Acceleration on Docker

Working with and as of: 01/12/2022

  • Ubuntu 20.04
  • Docker 20.10.7
  • Docker-compose 2.2.3
  • Nvidia Driver 495
  • Cuda 11.5

Introduction

This is a tutorial on how to run hardware acceleration for Jellyfin in a Docker container. If you have never used Jellyfin, it is an alternative to a popular media server called Plex. I recently learned about Jellyfin and have instantly fell in love. There is nothing behind a subscription unlike Plex. For example, you need a subcription to hardware accelerate transcode while it is complete included on Jellyfin.

What is transcoding?

Transcoding takes already compressed (or encoded) content, decompressing (decoding) that content, and then altering and compressing the content again. This is normally done to change the video and audio codec or simply known as format. For video it can be to convert MPEG2 source into H.264.

Difference between hardware acceleration.

‘Hardware acceleration is the use of computer hardware made to perform some functions more efficiently than in software running on a general-purpose central processing unit (CPU). Any transformation of data or routine that can be computed can be calculated purely in software running on a generic CPU, purely in custom-made hardware, or in some mix of both.’ Wikipedia

Now onto the steps!

This install will be based on Ubuntu 20.04 LTS. You will need Docker version greater than 19.X and docker compose version greater than 1.28.X. Below are all the commands to get going. The gist is installing docker, installing a compatible version of docker-compose, installing the nvidia container toolkit and driver version. Then getting the nfs-common so we can mount to a local NAS NFS share. After that all we would have to do is create the compose yaml and environment file. Once all that is done, you can reboot, then create your container!

1
2
3
4
sudo apt install docker.io
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker 

You will want to check the release page for the most current version of docker-compose.

1
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
1
sudo chmod +x /usr/local/bin/docker-compose
1
sudo apt install nvidia-container-toolkit

If yours can not find the toolkit, run this. Make sure you find your correct distro.

1
2
3
4
5
6
7
8
9
10
#Debian
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - 
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

#RHEL Based
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | \
sudo tee /etc/yum.repos.d/nvidia-docker.repo

The next 3 steps are to make sure you get the correct driver version, so just follow whichever it says is the recommended version for your GPU.

1
sudo add-apt-repository ppa:graphics-drivers/ppa
1
sudo apt install ubuntu-drivers-common
1
ubuntu-drivers devices

Sample output

1
2
3
4
5
6
7
8
9
10
11
vendor   : NVIDIA Corporation
model    : GP104 [GeForce GTX 1070]
driver   : nvidia-driver-390 - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-495 - distro non-free
driver   : nvidia-driver-450-server - distro non-free
driver   : nvidia-driver-460 - distro non-free
driver   : nvidia-driver-460-server - distro non-free
driver   : nvidia-driver-470 - distro non-free recommended
driver   : nvidia-driver-418-server - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin
1
sudo apt install -y nvidia-driver-495 #This would be where you could change the driver that was recommended
1
sudo usermod -aG video $USER
1
sudo apt update
1
sudo apt install -y nfs-common
1
sudo reboot
1
mkdir -p docker/jellyfin && cd docker/jellyfin
1
touch compose.yml
1
nano compose.yml

Note: This section assumes you have a folder called ~/media with a directory tv-shows and movies inside it, change this to where your media is located.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
version: "3.1"
services:
  jellyfin:
    image: jellyfin/jellyfin
    container_name: jellyfin
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=all
    volumes:
      - ${HOMEDIR}/docker/jellyfin/config:/config
      - ${HOMEDIR}/media/tv-shows:/data/tvshows
      - ${HOMEDIR}/media/movies:/data/movies
      - ${HOMEDIR}/docker/jellyfin/cache:/cache
    ports:
      - 8096:8096
      - 8920:8920 #optional for HTTPS
#      - 7359:7359/udp #optional
#      - 1900:1900/udp #optional
    restart: unless-stopped
    devices:
    - "/dev/nvidia0:/dev/nvidia0"
    deploy:
      resources:
        reservations:
          devices:
          - 'driver': 'nvidia'
            'count': 1
            'capabilities': ['gpu', 'utility', 'compute', 'video']
    devices:
      - /dev/nvidia-uvm:/dev/nvidia-uvm
      - /dev/nvidia-uvm-tools:/dev/nvidia-uvm-tools
1
nano .env

This section for the most part is good but you will just need to change your timezone.

1
2
3
4
HOMEDIR=${HOME}
PGID=1000
PUID=1000
TZ=America/Denver
1
sudo docker-compose up -d

Once you have it booted, you will go to the IP of the computer that is running the container with port 8096. Then go through the set up. If you are trying to find your media files and they are not showing up, then make sure your drive is still mounted. If all that is good, then run docker inspect jellyfin and scroll through the output and you will eventually find the bind mount of the container to your server. Make sure this is correct, if it is not then you will need to edit the .env file. Replace the ${HOME} with the directory to your home directory or to wherever you need it.

Then go to your dashboard > playback, turn on Nvidia encoding. Check all the boxes right below it for the video formats. Then scroll to the bottom and save. Now start a video and it should be playing.

This command is to make sure that everything is working. You should see percentage of usage. The top right should have Cuda showing up with a version, if it shows N/A then hardware acceleration will not work.

1
sudo docker exec -it jellyfin nvidia-smi

Congrats!

You now have jellyfin installed on a docker container with hardware acceleration! Enjoy your media, your way!

I will be posting about this turning into an ansible playbook so you dont have to do every step. Just enter a command and it sets up jellyfin.

This post is licensed under CC BY 4.0 by the author.