linuxserver / docker-jellyfin

GNU General Public License v3.0
630 stars 94 forks source link

Hardware transcoding dosen't work since 10.7.7-1-ls131 #129

Closed lemystere closed 2 years ago

lemystere commented 2 years ago

linuxserver.io


Expected Behavior

When hardware transcoding is enable in the settings, Jellyfin would transcode medias that need to be transcode or if the user wants to transcode because he wants a lower bitrate. Note that in the version 10.7.6-1-ls130 it's working perfectly fine.

Current Behavior

When hardware transcoding is enable, Jellyfin dosen't transcode.

Steps to Reproduce

  1. Install the image : 10.7.7-1-ls136
  2. Of course you need to update jellyfin-ffmpeg to the version 4.3.2-1 in your container
  3. Enable hardware transcoding in the settings of Jellyfin
  4. Force the transcoding when you play a media

Environment

OS: Ubuntu CPU architecture: x86_64 How docker service was installed: With "stacks" on Portainer.

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

version: "2.1"
services:
  jellyfin:
    image: lscr.io/linuxserver/jellyfin
    container_name: Jellyfin
    environment:
      - PUID=1002
      - PGID=100
    volumes:
      - /path to config:/config
      - /path to media:/media
    devices:
      - /dev/dri:/dev/dri
    ports:
      - 8096:8096
    restart: always

FFmpeg logs

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (h264_qsv) -> h264 (h264_qsv))
  Stream #0:2 -> #0:1 (eac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[AVHWDeviceContext @ 0x55c96f67d040] libva: /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so has no function __vaDriverInit_1_0
[AVHWDeviceContext @ 0x55c96f67d040] Failed to initialise VAAPI connection: -1 (unknown libva error).
Error creating a QSV device
qsv hwaccel requested for input stream #0:0, but cannot be initialized.
[h264_qsv @ 0x55c96f66f680] Error initializing the MFX video decoder: invalid handle (-6)
Error while decoding stream #0:0: Invalid argument
[AVHWDeviceContext @ 0x55c96f70c440] libva: /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so has no function __vaDriverInit_1_0
[AVHWDeviceContext @ 0x55c96f70c440] Failed to initialise VAAPI connection: -1 (unknown libva error).
Error creating a QSV device
qsv hwaccel requested for input stream #0:0, but cannot be initialized.
github-actions[bot] commented 2 years ago

Thanks for opening your first issue here! Be sure to follow the bug or feature issue templates!

tevenfeng commented 2 years ago

I tried the solution in this issue and it make my vaapi work. But quick sync just don't.

Prototyped commented 2 years ago

I fixed this for myself building a container based on the Linuxserver container for Jellyfin:

FROM ghcr.io/linuxserver/jellyfin

RUN set -ex; \
    env DEBIAN_FRONTEND=noninteractive apt -y update; \
    env DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends full-upgrade; \
    env DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install vainfo; \
    env DEBIAN_FRONTEND=noninteractive apt -y clean; \
    rm -rf /var/cache/apt/archives/*

RUN set -ex; \
    curl -fLSso /tmp/jellyfin-ffmpeg.deb 'https://repo.jellyfin.org/releases/server/ubuntu/versions/jellyfin-ffmpeg/4.3.2-1/jellyfin-ffmpeg_4.3.2-1-focal_amd64.deb'; \
    dpkg -i /tmp/jellyfin-ffmpeg.deb; \
    rm -f /tmp/jellyfin-ffmpeg.deb; \
    ln -f /usr/lib/x86_64-linux-gnu/libva* /usr/lib/jellyfin-ffmpeg/lib/

In effect it upgrades the OS, installs the correct jellyfin-ffmpeg package, and replaces the VA-API implementation that jellyfin-ffmpeg uses with the one from the OS. I have a cron job that tries to pull the ghcr.io/linuxserver/jellyfin container and, if there's a new version, rebuilds my Jellyfin container using the above Dockerfile.

ebb-earl-co commented 2 years ago

@Prototyped is this in essence what the Jellyfin-AMD Docker Mod does? I.e. could this be combined with that in order to get VAAPI working with AMD iGPUs?

Prototyped commented 2 years ago

Looks like that Docker mod installs (at container start rather than container build) Radeon DRI/DRM drivers and Mesa VA-API and VDPAU drivers from a third-party apt repo. My Dockerfile doesn't do that at all -- it just installs an up to date VA-API and then replaces the VA-API libraries under jellyfin-ffmpeg with it. You could combine them if you wanted -- nothing my Dockerfile does precludes the use of the Docker Mod -- but in my opinion if you're already building a container image, you're better off just doing it all directly in the Dockerfile rather than bothering with the Docker Mod.

ebb-earl-co commented 2 years ago

@Prototyped good call on the modifications all in Dockerfile; however this container already uses files in the /root/etc/cont-init.d directory, so they could just be added there? Also, in the Reddit link you included, the permissions on /dev/dri are specified as rwm, not rwx as you have it in your PR. Would you mind elaborating on that?

Prototyped commented 2 years ago

As I said there's nothing preventing anyone from just using the Docker Mod files. Having stuff installed on container launch isn't as good as actually baking the changes into the image though.

I don't think I included any Reddit link and didn't think I'd submitted a PR so unsure what you're talking about.

ebb-earl-co commented 2 years ago

Oh you're right, I'm getting my wires crossed with a different effort to change permissions to the /dev/dri directory, apologies! Thanks for the Dockerfile; I'm going to follow your lead with it

mbourd25 commented 2 years ago

Has this issue been looked at? I'm having the same error when the transcoding used to work before.

[AVHWDeviceContext @ 0x5582eb0ea7c0] libva: /usr/lib/x86_64-linux-gnu/dri/radeonsi_drv_video.so has no function __vaDriverInit_1_0 [AVHWDeviceContext @ 0x5582eb0ea7c0] Failed to initialise VAAPI connection: -1 (unknown libva error). Device creation failed: -5. Failed to set value '/dev/dri/renderD128' for option 'vaapi_device': Input/output error Error parsing global options: Input/output error

Here is my Docker-Compose:

version: "2.1" services: jellyfin: image: ghcr.io/linuxserver/jellyfin container_name: jellyfin group_add:

Let me know if more information is required.

juic3pow3rs commented 2 years ago

The issue seems to persist with ls143, the fix @Prototyped provided above still does the trick though.

mbourd25 commented 2 years ago

The issue seems to persist with ls143, the fix @Prototyped provided above still does the trick though.

Hi @juic3pow3rs, how do you use @Prototyped code?

Thanks

lemystere commented 2 years ago

@mbourd25 You can simply do :

sudo docker exec -it "Name of your Jellyfin container" bash
apt -y update && apt -y --no-install-recommends full-upgrade && apt -y --no-install-recommends install vainfo && apt -y clean && rm -rf /var/cache/apt/archives/* && curl -fLSso /tmp/jellyfin-ffmpeg.deb 'https://repo.jellyfin.org/releases/server/ubuntu/versions/jellyfin-ffmpeg/4.3.2-1/jellyfin-ffmpeg_4.3.2-1-focal_amd64.deb' && dpkg -i /tmp/jellyfin-ffmpeg.deb && rm -f /tmp/jellyfin-ffmpeg.deb && ln -f /usr/lib/x86_64-linux-gnu/libva* /usr/lib/jellyfin-ffmpeg/lib/

Warning, if you update your container, you have to re-do these two commands.

mbourd25 commented 2 years ago

Hi @lemystere, sorry for the lateness in my response, your command works like a charm. AMD transcoding is back working.

How can we tell the Jellyfin developers about this?

Thanks for the help.

lemystere commented 2 years ago

Hell @mbourd25, I guess we are at the right place. But it’s a well known problem if you install Jellyfin "manually" so I imagine there is not a lot to do about it.

Also, if you don't want to re-do the command evry time you update, you can create the script below in order to update Jellyfin. You have to create a file with a '.sh" extension in your folder "/path to config/jellyfin/custom-cont-init.d/". In the file you have to write :

if [[ "$(apt list jellyfin-ffmpeg 2>/dev/null | sed '2q;d')" != "jellyfin-ffmpeg/now 4.3.2-1-focal amd64 [installed,local]" ]]; then
  echo "**** update transcoding ****"
  apt -y update
  apt -y --no-install-recommends full-upgrade
  apt -y --no-install-recommends install vainfo
  apt -y clean && rm -rf /var/cache/apt/archives/* 
  curl -fLSso /tmp/jellyfin-ffmpeg.deb 'https://repo.jellyfin.org/releases/server/ubuntu/versions/jellyfin-ffmpeg/4.3.2-1/jellyfin-ffmpeg_4.3.2-1-focal_amd64.deb' 
  dpkg -i /tmp/jellyfin-ffmpeg.deb 
  rm -f /tmp/jellyfin-ffmpeg.deb 
  ln -f /usr/lib/x86_64-linux-gnu/libva* /usr/lib/jellyfin-ffmpeg/lib/
fi

Every time your container will start, this script will be read. If your jellyfin-ffmpeg is already on the good version this script will do nothing. If not, the script will update to the good version like the command before.

abayomi185 commented 2 years ago

Also, if you don't want to re-do the command evry time you update, you can create the script below in order to update Jellyfin. You have to create a file with a '.sh" extension in your folder "/path to config/jellyfin/custom-cont-init.d/". In the file you have to write :

if [[ "$(apt list jellyfin-ffmpeg 2>/dev/null | sed '2q;d')" != "jellyfin-ffmpeg/now 4.3.2-1-focal amd64 [installed,local]" ]]; then
  echo "**** update transcoding ****"
  apt -y update
  apt -y --no-install-recommends full-upgrade
  apt -y --no-install-recommends install vainfo
  apt -y clean && rm -rf /var/cache/apt/archives/* 
  curl -fLSso /tmp/jellyfin-ffmpeg.deb 'https://repo.jellyfin.org/releases/server/ubuntu/versions/jellyfin-ffmpeg/4.3.2-1/jellyfin-ffmpeg_4.3.2-1-focal_amd64.deb' 
  dpkg -i /tmp/jellyfin-ffmpeg.deb 
  rm -f /tmp/jellyfin-ffmpeg.deb 
  ln -f /usr/lib/x86_64-linux-gnu/libva* /usr/lib/jellyfin-ffmpeg/lib/
fi

Thanks! @lemystere

I suppose the script should be made executable too.

Pl1997 commented 2 years ago

@mbourd25 You can simply do :

sudo docker exec -it "Name of your Jellyfin container" bash
apt -y update && apt -y --no-install-recommends full-upgrade && apt -y --no-install-recommends install vainfo && apt -y clean && rm -rf /var/cache/apt/archives/* && curl -fLSso /tmp/jellyfin-ffmpeg.deb 'https://repo.jellyfin.org/releases/server/ubuntu/versions/jellyfin-ffmpeg/4.3.2-1/jellyfin-ffmpeg_4.3.2-1-focal_amd64.deb' && dpkg -i /tmp/jellyfin-ffmpeg.deb && rm -f /tmp/jellyfin-ffmpeg.deb && ln -f /usr/lib/x86_64-linux-gnu/libva* /usr/lib/jellyfin-ffmpeg/lib/

Warning, if you update your container, you have to re-do these two commands.

Thanks a huge lot for this ! In order to make this workaround work, I also had to add two environments variable : LIBVA_DRIVERS_PATH=/usr/lib/jellyfin-ffmpeg/lib/dri and LIBVA_DRIVER_NAME=i965 (maybe related to #105 and #102 ?)

Please tell me if I can provide any useful info to fix these issues !

abayomi185 commented 2 years ago

Hey @Pl1997 The latest image works for me and has been fixed; #136

Pl1997 commented 2 years ago

Thanks for the heads up but unfortunately I am already running the latest image... I suppose #136 wasn't able to solve my issue because I'm using i965 driver (I have an old N3060 processor, I guess that's why it doesn't work with iHD...)

lemystere commented 2 years ago

It's seems that the new versions solve this issue.