linuxserver / docker-jellyfin

GNU General Public License v3.0
647 stars 97 forks source link

Hardware acceleration isn't working properly #26

Closed fengapappit closed 2 years ago

fengapappit commented 4 years ago

Expected Behavior

Enabling VAAPI hardware acceleration in Jellyfin should work in its default configuration.

Current Behavior

First issue is with the default transcode directory. As it does not exist and Jellyfin doesn't create it, it's impossible to use the default configuration.

Secondly, once the devices are setup according to my host, the default user is not able to access them. Any transcode attempt leads to the following error message:

/usr/lib/jellyfin-ffmpeg/ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -i file:"/jellyfin/media/12 Angry Men (1957)/12 Angry Men (1957) Bluray-1080p.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_vaapi  -b:v 10201576 -maxrate 10201576 -bufsize 20403152 -profile:v high -level 41  -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -vf "format=nv12|vaapi,hwupload,scale_vaapi=format=nv12" -copyts -vsync -1 -codec:a:0 aac -strict experimental -ac 1 -ab 192000  -f hls -max_delay 5000000 -avoid_negative_ts disabled -start_at_zero -hls_time 3 -individual_header_trailer 0 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "/config/cache/temp/69e65dd7670476af5b32268cf32dcb6f%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "/config/cache/temp/69e65dd7670476af5b32268cf32dcb6f.m3u8"

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
  configuration: --toolchain=hardened --prefix=/usr --target-os=linux --enable-cross-compile --extra-cflags=--static --enable-gpl --enable-static --disable-doc --disable-ffplay --disable-shared --disable-libxcb --disable-sdl2 --disable-xlib --enable-libfontconfig --enable-fontconfig --enable-gmp --enable-gnutls --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libwebp --enable-libx264 --enable-libx265 --enable-libzvbi --enable-omx --enable-omx-rpi --enable-version3 --enable-vaapi --enable-vdpau --arch=amd64 --enable-nvenc --enable-nvdec --enable-amf
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[AVHWDeviceContext @ 0x563fc93af5c0] No VA display found for device /dev/dri/renderD128.
Device creation failed: -22.
Failed to set value '/dev/dri/renderD128' for option 'vaapi_device': Invalid argument
Error parsing global options: Invalid argument

When running the same exact command through a root shell to the docker, it works as expected and transcoding works.

I've tried adding the abc user to the video group, doesn't change anything.

Same thing for running the docker container as high privilege.

I wanted to try running the service as root but I can't find what is starting the service nor where I can configure this. I got lost in /etc/s6 as I'm completely unfamiliar with it.

Steps to Reproduce

  1. Enable VAAPI transcoding in Playback options and save the settings
  2. Notice that it gives an error concerning the transcode directory
  3. Re-enable VAAPI and change the directory to something existing, such as /config/cache/temp/ and save the settings
  4. Try playing anything needing transcode

Environment

OS:

Synology DSM 6.2.2-24922 Update 4

CPU architecture:

INTEL Celeron J3455

How docker service was installed:

Docker was installed through Synology store. Same for the image. Since it does not support custom configuration, especially the devices, I had to import the following configuration file to make it work:

{
   "cap_add" : null,
   "cap_drop" : null,
   "cmd" : "",
   "cpu_priority" : 50,
   "devices" :  [
       { 
           "CgroupPermissions": "rwm", 
           "PathInContainer": "/dev/dri/renderD128", 
           "PathOnHost": "/dev/dri/renderD128" 
       },
       { 
           "CgroupPermissions": "rwm", 
           "PathInContainer": "/dev/dri/card0", 
           "PathOnHost": "/dev/dri/card0" 
       }
   ],
   "enable_publish_all_ports" : false,
   "enable_restart_policy" : false,
   "enabled" : false,
   "entrypoint_default" : "/init",
   "env_variables" : [
      {
         "key" : "PATH",
         "value" : "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
      },
      {
         "key" : "HOME",
         "value" : "/root"
      },
      {
         "key" : "LANGUAGE",
         "value" : "en_US.UTF-8"
      },
      {
         "key" : "LANG",
         "value" : "en_US.UTF-8"
      },
      {
         "key" : "TERM",
         "value" : "xterm"
      },
      {
         "key" : "NVIDIA_DRIVER_CAPABILITIES",
         "value" : "compute,video,utility"
      },
      {
         "key" : "PGID",
         "value" : "101"
      },
      {
         "key" : "PUID",
         "value" : "1026"
      }
   ],
   "exporting" : false,
   "id" : "851b673d1b03caae27ad79561568172a9b7b8525bd01687582b85927686deef3",
   "image" : "linuxserver/jellyfin:latest",
   "is_ddsm" : false,
   "is_package" : false,
   "links" : [],
   "memory_limit" : 0,
   "name" : "linuxserver-jellyfin-latest",
   "network" : [
      {
         "driver" : "bridge",
         "name" : "bridge"
      }
   ],
   "network_mode" : "bridge",
   "port_bindings" : [
      {
         "container_port" : 8096,
         "host_port" : 0,
         "type" : "tcp"
      },
      {
         "container_port" : 8920,
         "host_port" : 0,
         "type" : "tcp"
      }
   ],
   "privileged" : false,
   "shortcut" : {
      "enable_shortcut" : false
   },
   "use_host_network" : false,
   "volume_bindings" : [
      {
         "host_volume_file" : "/test",
         "mount_point" : "/jellyfin/media",
         "type" : "rw"
      }
   ]
}

Command used to create docker container (run/create/compose/screenshot)

image

The previously mentioned configuration pretty much maps to a docker compose command.

I'd be glad if you could provide a tip in changing the user running the Jellyfin service from abc to root as a quick fix, as everything I've tried didn't work.

aptalca commented 4 years ago

No vaapi support on arm64. It's for Intel gpus

fengapappit commented 4 years ago

No vaapi support on arm64. It's for Intel gpus

My bad, I read amd64. It is indeed an intel CPU with integrated graphics. I'll correct the post.

Artiume commented 4 years ago

So 10.5.X0 has some issues that we're working out. It requires non-free drivers to work right now. Try this

sudo docker exec -it -u 0 jellyfin echo "deb http://http.us.debian.org/debian stable main contrib non-free" | sudo tee -a /etc/apt/sources.list
sudo docker exec -it -u 0 jellyfin apt update
sudo docker exec -it -u 0 jellyfin apt install i965-va-driver-shaders

https://packages.debian.org/sid/i965-va-driver-shaders

fengapappit commented 4 years ago

That's what I ended up doing on the official docker, but how come that it works using the root account but not the normal one on your docker build ?

That broke my mind for days before having to cut my losses and let Jellyfin win the battle for a while.

Le mar. 7 avr. 2020 à 13:14, artiume notifications@github.com a écrit :

So 10.5.X0 has some issues that we're working out. It requires non-free drivers to work right now. Try this

sudo docker exec -it -u 0 jellyfin echo "deb http://http.us.debian.org/debian stable main contrib non-free" | sudo tee -a /etc/apt/sources.list sudo docker exec -it -u 0 jellyfin apt update sudo docker exec -it -u 0 jellyfin apt install i945-va-driver-shaders

https://packages.debian.org/sid/i965-va-driver-shaders

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/linuxserver/docker-jellyfin/issues/26#issuecomment-610326751, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUWTQ5BRHVNRJHMYPMEKEDRLMDIBANCNFSM4LW2SRNA .

Artiume commented 4 years ago

So if root works but the user doesn't, that breaks down to a simple permissions issue. Did you add the user to the video group?

For jellyfin/jellyfin it becomes more complicated by requiring stuff like group_add

fengapappit commented 4 years ago

Yes, I've tried it. Didn't change anything unfortunately.

Le mar. 7 avr. 2020 à 14:32, artiume notifications@github.com a écrit :

So if root works but the user doesn't, that breaks down to a simple permissions issue. Did you add the user to the video group?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/linuxserver/docker-jellyfin/issues/26#issuecomment-610359238, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUWTQ3M5DJ7E5QCJLLKUQDRLMMO7ANCNFSM4LW2SRNA .

aptalca commented 4 years ago

It's likely not working because you're not following our samples in the readme. You need to pass the device "--device /dev/dri", instead of passing render and card0 separately

Artiume commented 4 years ago

Try chmod 777 the devices and see what happens. Maybe the libraries have perm issues as well.

I'm not familiar with DSM so it might be something else I'm not aware of

Edit: try @aptalca's solution

Legogris commented 4 years ago

@aptalca There was a 10.5.4 release today that fixes a regression issue with VAAPI for MPEG 4: https://github.com/jellyfin/jellyfin/pull/2821

That doesn't seem to be the issue for you though @fengapappit. To extend on what was commented above: Check on your host where your devices are mounted. For me (on an Intel with i915):

$ ls -l /dev/dri
total 0
drwxr-xr-x 2 root root         80 Apr  7 02:41 by-path
crw-rw---- 1 root video  226,   0 Apr  7 02:41 card0
crw-rw---- 1 root render 226, 128 Apr  7 02:41 renderD128

So in my case, first as suggested configure the container top mount device /dev/dri on host to /dev/dri in container, then configure VA API device to /dev/dri/renderD128 in jellyfin.

TwoBall commented 4 years ago

I think it is because the set PUID does not have permission. Synology's /dev/dri/renderD128 permissions are crw------- 1 root root ,and PGID specified user group does not have permission to RW I try to use chmod 666 /dev/dri/renderD128 solved this problem,But every time Synology restarts, the permissions will be restored. This is not a problem with jellyfin, because I use Emby-docker will also have this problem, but Emby SPK does not have this problem, it will set the permissions.

aptalca commented 4 years ago

The permissions are automatically fixed as long as the mount points are as suggested in our readmes

fmanno commented 4 years ago

The permissions are automatically fixed as long as the mount points are as suggested in our readmes

I've ran into this exact same issue today unfortunately this is not true. I've created the container as per the readme, like this:

sudo docker create \
  --name=jellyfin \
  -e PUID=1002 \
  -e PGID=100 \
  -e TZ=Europe/London \
  -p 8096:8096 \
  -v /share/appdata/jellyfin:/config \
  -v /share/Media:/data \
  --device /dev/dri:/dev/dri \
  --restart unless-stopped \
  linuxserver/jellyfin

and I've also tried:

sudo docker create \
  --name=jellyfin \
  -e PUID=1002 \
  -e PGID=100 \
  -e TZ=Europe/London \
  -p 8096:8096 \
  -v /share/appdata/jellyfin:/config \
  -v /share/Media:/data \
  --device /dev/dri/renderD128:/dev/dri/renderD128 \
  --device /dev/dri/card0:/dev/dri/card0 \
  --restart unless-stopped \
  linuxserver/jellyfin

and permissions of the devices, in both cases, are:

# ls -al /dev/dri
total 0
drwxr-xr-x 2 root root       80 Apr 22 23:13 .
drwxr-xr-x 6 root root      360 Apr 22 23:13 ..
crw------- 1 root root 226,   0 Apr 22 23:13 card0
crw------- 1 root root 226, 128 Apr 22 23:13 renderD128

After running: # chmod 777 /dev/dri/*

Transcoding works as expected. Perhaps this is the same problem as this plex issue #207

aptalca commented 4 years ago

Are these all synology's? What kind of Mickey Mouse stuff is this with the video devices root owned and no group rw?

There is nothing we can do for that scenario, you gotta fix the perms on host and report it to synology

EDIT: I missed the missing group rw in the prior post. To clarify, as long as the devices have group access, our container works. All other OSes I have seen have the group permissions on devices. The owners differ, but the group perms are there.

fmanno commented 4 years ago

In my case it's a Qnap TS-251+ NAS, I understand your point @aptalca, it's impossible to cater for all corner cases. I really appreciate all the work you guys do so we can use these apps.

Do you think perhaps this is worth a mention in the readme though?

For anybody else looking for a workaround, the containers are setup to run custom scripts at init (also not in the readme, maybe it could be included?) so I just created a script in: /config/custom-cont-init.d/fix-dri-permissions (this is the container path)

#!/usr/bin/with-contenv bash

# check for the existence of a video device
if [ -e /dev/dri ]; then
    echo "Running: chmod 755 /dev/dri/*"
    chmod 755 /dev/dri/*
else
    exit 1
fi

And it now works and should be persistent if I ever update the container as long as I map the same host folder to the container /config folder.

aptalca commented 4 years ago

Yeah, we'll update the info. Thanks for letting us know

Legogris commented 4 years ago

Food for though for those who are having problems with permissions: Does running via podman (still using this image) instead of via docker make it easier to secure things?

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ageekhere commented 3 years ago

Just upgraded ubuntu to 20.04.1 LTS from 18.04 LTS and hardware acceleration stopped working. sudo chmod 666 /dev/dri/renderD128 fixed the issue.

ocervell commented 3 years ago

@Artiume I believe the cmds you copied would fix my problem, but when I try to add the repo, I get:

W: GPG error: http://http.us.debian.org/debian stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 04EE7237B7D453EC NO_PUBKEY 648ACFD622F3D138 NO_PUBKEY DCC9EFBF77E11517
Artiume commented 3 years ago

we updated the key so make sure you have the right key now.

wget -O - https://repo.jellyfin.org/debian/jellyfin_team.gpg.key | sudo apt-key add - echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/debian $( lsb_release -c -s ) main" | sudo tee /etc/apt/sources.list.d/jellyfin.list

ocervell commented 3 years ago

@Artiume it did not change the issue I had above, which I believe is related to http://http.us.debian.org/debian repo, not the Jellyfin repo. Couldn't find the new public key for that one ...

Artiume commented 3 years ago

So is this being done on the host or within the container? afaik the lsio container should be updated to the new key.

ocervell commented 3 years ago

Ok, I managed to fix the key problem by running:

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC
Executing: /tmp/apt-key-gpghome.8XdSbMqvNU/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC
gpg: key E0B11894F66AEC98: 14 signatures not checked due to missing keys
gpg: key E0B11894F66AEC98: public key "Debian Archive Automatic Signing Key (9/stretch) <ftpmaster@debian.org>" imported
gpg: Total number processed: 1
gpg:               imported: 
apt update
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://http.us.debian.org/debian stable InRelease
Hit:5 https://repo.jellyfin.org/ubuntu bionic InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
191 packages can be upgraded. Run 'apt list --upgradable' to see them.

but I still cannot install i945-va-driver-shaders ....

# apt install i945-va-driver-shaders
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package i945-va-driver-shaders

PS: This is done within the container, I'm using linuxserver/jellyfin:bionic-version-10.6.4-1 image.

mrhotio commented 3 years ago

You can't install a non existing package...

Try i965-va-driver-shaders

ocervell commented 3 years ago

Whoops ! @Artiume you might want to correct your existing comment to i965-va-driver-shaders. Ok, so I managed to install it and transcoding seems to work but hardware acceleration is still not active:

Stream mapping: Stream #0:2 -> #0:0 (hevc (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (eac3 (native) -> mp3 (libmp3lame))

VAInfo output:

# vainfo
error: XDG_RUNTIME_DIR not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.4.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_4
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.4 (libva 2.4.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Gemini Lake - 2.3.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointEncSliceLP
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointEncSliceLP
      VAProfileH264MultiviewHigh      : VAEntrypointVLD
      VAProfileH264MultiviewHigh      : VAEntrypointEncSlice
      VAProfileH264StereoHigh         : VAEntrypointVLD
      VAProfileH264StereoHigh         : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileJPEGBaseline           : VAEntrypointEncPicture
      VAProfileVP8Version0_3          : VAEntrypointVLD
      VAProfileVP8Version0_3          : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointEncSlice
      VAProfileVP9Profile2            : VAEntrypointVLD

Package install:

# apt install i965-va-driver-shaders
Reading package lists... Done
Building dependency tree
Reading state information... Done
i965-va-driver-shaders is already the newest version (2.3.0-1).
The following packages were automatically installed and are no longer required:
  libpython3.6 libpython3.6-minimal libpython3.6-stdlib
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 186 not upgraded.

NB: I'm running the container with high privilege enabled.

ocervell commented 3 years ago

Edit: it's working ! Had to enable hardware transcoding for h264 as well as HEVC in Jellyfin settings ...

AlexKalopsia commented 3 years ago

Running on the same issue and yup, I "solved" it by running chmod 777 /dev/dri/* as suggested by @fmanno

Is there any way to make this fix somehow permanent? I am also on a Syno.

imavroukakis commented 3 years ago

Running on the same issue and yup, I "solved" it by running chmod 777 /dev/dri/* as suggested by @fmanno

Is there any way to make this fix somehow permanent? I am also on a Syno.

Have you tried using Task Scheduler? image

image

Trying it out myself now

rightsaidfred99 commented 3 years ago

Running on the same issue and yup, I "solved" it by running chmod 777 /dev/dri/* as suggested by @fmanno

Is there any way to make this fix somehow permanent? I am also on a Syno.

Help a noob out, where do I enter this command in? The Terminal in the Docker Container in Synology?

AlexKalopsia commented 3 years ago

You can either do it from terminal establishing an SSH connection (you will find plenty tutorials for Syno), or just creating a scheduled task (like shown above ) and putting just that code in

rightsaidfred99 commented 3 years ago

Thanks, I did that and it works now. 

Although Intel Quick Sync seems to be very slow for me. The videos, especially 4k are transcoding, but on a DS918+, it stutters every 5 seconds and is pretty much unwatchable. 

20 June 2021, 16:23 by @.***:

You can either do it from terminal establishing an SSH connection (you will find plenty tutorials for Syno), or just creating a scheduled task (like shown above ) and putting just that code in

— You are receiving this because you commented. Reply to this email directly, > view it on GitHub https://github.com/linuxserver/docker-jellyfin/issues/26#issuecomment-864506360> , or > unsubscribe https://github.com/notifications/unsubscribe-auth/AR2VQF5BL4KBQY3C5C5PHADTTWCPBANCNFSM4LW2SRNA> .

imavroukakis commented 3 years ago

Running on the same issue and yup, I "solved" it by running chmod 777 /dev/dri/* as suggested by @fmanno Is there any way to make this fix somehow permanent? I am also on a Syno.

Have you tried using Task Scheduler? image

image

Trying it out myself now

That worked great over a reboot. @ondrejmo perhaps you have a better suggestion?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ocervell commented 3 years ago

+1 on @rightsaidfred99 comment, hardware acceleration works but for 4k HEVC files I get stutter every 5 seconds if quality is set to any higher preset than 1080 - 20Mbps... My network bandwith is 1Gb and have a decent Synology DS920+ NAS.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

j0nnymoe commented 2 years ago

Closing this as lots has changed since this was originally opened in terms of the drivers and hardware acceleration.

Please re-open a fresh ticket if this is still an issue.