xemle/home-gallery

Docker image variant for Intel QuickSync transcoding

Opened this issue · 6 comments

First of all, great work on this project!

I'm curious if there is a plan to offer an option that supports Intel QuickSync (not limited to others hardware acceleration like Nvenc)?

Reason is I'm dabbling with home lab server and I got Jellyfin running with Intel QuickSync through Docker using linuxserver image: https://hub.docker.com/r/linuxserver/jellyfin

Currently I'm using your xemle/home-gallery image and realise it is using node alpine as the base image that I suspects is the culprit as there is no working driver in the docker image when trying to use QuickSync through the video extractor ffmpeg args.

Here's the error message when I try to run ffmpeg inside the container:

[AVHWDeviceContext @ 0x7f2cc24a7f80] libva: VA-API version 1.21.0
[AVHWDeviceContext @ 0x7f2cc24a7f80] libva: User requested driver 'iHD'
[AVHWDeviceContext @ 0x7f2cc24a7f80] libva: Trying to open /usr/lib/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x7f2cc24a7f80] libva: va_openDriver() returns -1
[AVHWDeviceContext @ 0x7f2cc24a7f80] Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
Failed to set value '/dev/dri/renderD128' for option 'qsv_device': I/O error
Error parsing global options: I/O error

The command that I used that works in the Jellyfin container but produce the error above in HomeGallery container:

ffmpeg -loglevel verbose -hwaccel qsv -qsv_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i "foo.mkv" foo.mp4

As I'm familiar with Docker, I'll try to modify the Dockerfile and see how it goes. Probably I'll need to refer to the Jellyfin Dockerfile too to see if I need to do anything extra.

Thanks again for this great project! Images just works but I wanted to include videos that got me noticed the max out CPU usage from ffmpeg conversion that got me disabling the video extraction temporarily.

Hi @hueyyeng Thank you for reaching out and trying HomeGallery

Is that kind of FYI since you are trying to build your own Docker container? Or do you need any support?

Regarding Intel QuickSync I can not help here because I do not own such hardware.

This is more of trying to get Intel QuickSync working inside the Docker container as the ffmpeg args is helpful if one want to utilise the hardware encoding.

I'll share my results here once I got it working so others can benefit from it.


Edit: I manage to use linuxserver/ffmpeg image as my base and manually added node for the gallery image. Although I kept encountering ffmpeg exit code errors when debugging the video extractor.

Turns out the video extractor plugin uses fluent ffmpeg and I need to add inputOptions to the command which got it working.

I need to check the documentation for writing plugins but the only changes I did is the inputOptions after checking fluent ffmpeg docs.

I'll share my solution later once I done a few more testing but for others who are interested in getting a working Intel QuickSync transcoding for homegallery in Docker (before I forget):

  1. Prepare a new Dockerfile or make a copy of the existing Dockerfile. I recommend cloning with git and directly modify the existing Dockerfile as I can track the diff using git.
  2. Use linuxserver/ffmpeg docker image as your base.
  3. Add node and yarn. I'm using node bookworm slim Dockerfile.
  4. Once build, enter the gallery container using bash and verify ffmpeg with QuickSync encoding is working.

Make sure to pass the Intel GPU device to the docker.

You are using vaapi output format.
-hwaccel_output_format vaapi

Change it to qsv
-hwaccel qsv -hwaccel_output_format qsv

Should work in current image also

Everything available with just passed iGPU to container without any magic

~ $ ffmpeg -decoders|grep qsv
ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13.2.1 (Alpine 13.2.1_git20240309) 20240309
  configuration: --prefix=/usr --disable-librtmp --disable-lzma --disable-static --disable-stripping --enable-avfilter --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libmp3lame --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librist --enable-libsoxr --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-lto=auto --enable-lv2 --enable-openssl --enable-pic --enable-postproc --enable-pthreads --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-vulkan --optflags=-O3 --enable-libjxl --enable-libsvtav1 --enable-libvpl
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
 V....D av1_qsv              AV1 video (Intel Quick Sync Video acceleration) (codec av1)
 V....D h264_qsv             H264 video (Intel Quick Sync Video acceleration) (codec h264)
 V....D hevc_qsv             HEVC video (Intel Quick Sync Video acceleration) (codec hevc)
 V....D mjpeg_qsv            MJPEG video (Intel Quick Sync Video acceleration) (codec mjpeg)
 V....D mpeg2_qsv            MPEG2VIDEO video (Intel Quick Sync Video acceleration) (codec mpeg2video)
 V....D vc1_qsv              VC1 video (Intel Quick Sync Video acceleration) (codec vc1)
 V....D vp8_qsv              VP8 video (Intel Quick Sync Video acceleration) (codec vp8)
 V....D vp9_qsv              VP9 video (Intel Quick Sync Video acceleration) (codec vp9)
~ $ 
Screenshot 2024-10-02 at 01 46 42 Screenshot 2024-10-02 at 01 50 27

Something like that should help.

I still not as familiar as wanted with that. As I understand qsv - is one concrete driver and device. vaapi - abstraction over some of them. vaapi looks like more flexible for this case.

For example when I've tried qsv - ffmpeg wanted one particular driver, but vaapi checked one by one in list.
and also current settings api enough for hardware encoding (we can pass encoding parameters)
but hw decoding not accesible from user side and config. So in current implementation we can use only hw encoding.
(after adding needed drivers in Dockerfile)

@hueyyeng
I've made some investigation. Hope it will help but I'm not sure I can spend more effort to it. Maybe someone can make it useful for public.

In our case we have ffmpeg compiled without qsv support. Only vaapi, but seems like it is not so important for such tasks.

#157