Stremio / server-docker

Builds and publishes Docker image for new releases of server.js
GNU General Public License v2.0
89 stars 16 forks source link

Unraid + Transcoding/Hardware acceleration #28

Open sigh-straits opened 6 months ago

sigh-straits commented 6 months ago

First of all, thanks for the dockerized version of the Stremio Service. Was able to follow documentation and run it in Unraid (if you're not familiar, it is a Linux-based OS for self-hosting servers and NAS). Managed to install some addons and currently able to proxy stream using Stremio Web. So, the main functionality is working.

I saw that ffmpeg-jellyfin is being used, and in Unraid I also have a Jellyfin server docker running, with GPU transcoding capabilities (in my specific case using NVIDIA GPU and nvenc). Tried the same docker configuration as described here for stremio-server, but to no avail. I guess some additional configuration would be necessary, even if similar ffmpeg version is available.

Since I'm not that knowledgeable regarding ffmpeg and video decoding/transcoding aspects or how the Stremio Service works, I am reaching for extra help... When testing, only CPU is being used, at least I see persistent spiking in CPU usage when watching content, so is there a way to had GPU hardware acceleration/transcoding functionality? Or is this already available and I missed it?

Even if not specifically for Unraid, was someone able to get this working for Linux platform? Any help or feedback welcome. Thanks.

jaruba commented 6 months ago

i'm uncertain of how much i will be able to help as we never tested the case of nvenc in a docker container

the server itself does profiling to attempt to figure out what hwaccel methods are supported on the system

as far as i understand the issue with using hwaccel in docker is that the docker container does not normally have access to the GPU, so i expect the issue to be the fact that our Dockerfile does not give the required access to the GPU

there is a community PR with this minor change: https://github.com/Stremio/server-docker/pull/24/files

that i believe might be specific to giving the required access to use the nvenc hwaccel method, but we didn't test it yet, if u could test it and confirm that the change (including the steps u followed from the jellyfin docs) work in your case, then we could potentially merge it

sigh-straits commented 6 months ago

@jaruba Thanks for the input

I tried taking a look at the community PR you mentioned, as well as the NVIDIA documentation for dockerized containers and other containers I have successfully managed to have hardware transcoding.

So, the change in the PR habilitates GPU capabilities for video purposes. Tried both NVIDIA_DRIVER_CAPABILITIES=video and NVIDIA_DRIVER_CAPABILITIES=all (something that works in other containers), even included my GPU id as supported device (NVIDIA_VISIBLE_DEVICES=GPU-xxxxxxxx or NVIDIA_VISIBLE_DEVICES=all in order to accept any). This had the NVIDIA runtime available in the container, by running nvidia-smi I see my GPU information present.

When I tried to play some content (used Sintel magnet URL + Torrentio), the movie played without issues, but without using hardware acceleration, relying still in CPU.


Made a different test, accessed the container via bash and runned this ffmpeg command: /usr/lib/jellyfin-ffmpeg/ffmpeg -c:v h264_cuvid -i "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" -map 0 -c:v hevc_nvenc -cq:v 19 -b:v 1491k -minrate 1043k -maxrate 1938k -bufsize 2983k -spatial_aq:v 1 -rc-lookahead:v 32 -c:a copy -c:s copy -max_muxing_queue_size 9999 -map -0:d output.mp4 (took the command from a transcoding tool i have that uses ffmpeg as well and GPU transcoding using NVENC)

When using this command inside the docker container, I was successfuly able to use hardware transcoding with my NVIDIA GPU. Screenshot 2024-01-08 at 14 11 18 The process list appears empty, but the GPU utilization was consistently at 33% usage and the GPU process was visible in my Unraid dashboard.


Therefore, providing the dockerized container with GPU capabilities is possible, and ffmpeg-jellyfin can use nvenc as expected. Could the problem then be related with Stremio Service implementation? Is there something that could be configured in order to force ffmpeg to use nvenc profile or something similar to that?

Hope this helps, if more information needed, please let me know. Thanks.