Open gmsotavio opened 11 months ago
Everything looks like it SHOULD be working.
try using the default path for FFmpeg instead of the one created by lffmpeg. does it use -hwaccel vaapi
when being invoked?
Hi @Thefrank
When attempting to use the default FFmpeg (6.0) on FreeBSD, an error occurs
The log displays the following command invocations:
ffmpeg -analyzeduration 200M -i file:"/mnt/downloads/Noah (2014) [2160p] [4K] [WEB] [5.1] [YTS.MX]/Noah.2014.2160p.4K.WEB.x265.10bit.AAC5.1-[YTS.MX].mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_vaapi -rc_mode VBR -b:v 6388419 -maxrate 6388419 -bufsize 12776838 -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale=trunc(min(max(iw\,ih*a)\,min(3658\,2074*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(3658/a\,2074))/2)*2,format=nv12,hwupload=derive_device=vaapi" -codec:a:0 aac -ac 2 -ab 384000 -ar 48000 -af "volume=2" -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "/var/db/jellyfin/transcodes/d84f765d6274cffe000f265bd429c904%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "/var/db/jellyfin/transcodes/d84f765d6274cffe000f265bd429c904.m3u8"
As we can see, -hwaccel vaapi
is missing and the following error is printed int the log
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_vaapi))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[hwupload @ 0x867e07c00] A hardware device reference is required to upload frames to.
[Parsed_hwupload_3 @ 0x860829e00] Query format failed for 'Parsed_hwupload_3': Invalid argument
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
[aac @ 0x860963c00] Qavg: 65536.000
[aac @ 0x860963c00] 2 frames left in the queue on closing
Conversion failed!
It appears that the following configuration is not being passed to FFmpeg. I am unsure how the device node path is handled by Jellyfin.
@gmsotavio hwupload=derive_device=vaapi
. that line should be handling it but it does not appear to be
but it also should do -init_hw_device
at some point too.
You can try changing the last line in lffmpeg
to ffmpeg -init_hw_device vaapi=va:/dev/dri/renderD128 -filter_hw_device va -hwaccel vaapi -hwaccel_output_format vaapi "$@"
and see if that is the nudge it needs
One final thing to try:
pkg remove libva-intel-media-driver
pkg install libva-intel-driver
@gmsotavio
hwupload=derive_device=vaapi
. that line should be handling it but it does not appear to be but it also should do-init_hw_device
at some point too. You can try changing the last line inlffmpeg
toffmpeg -init_hw_device vaapi=va:/dev/dri/renderD128 -filter_hw_device va -hwaccel vaapi -hwaccel_output_format vaapi "$@"
and see if that is the nudge it needs
@Thefrank, thank you for your patience and support.
As you have suggested, I have been trying to use FFmpeg with the following command to utilize VA-API for hardware acceleration:
ffmpeg -init_hw_device vaapi=va:/dev/dri/renderD128 -filter_hw_device va -hwaccel vaapi -hwaccel_output_format vaapi "$@"
However, I encountered the following error message during the process:
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_vaapi))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Impossible to convert between the formats supported by the filter 'Parsed_setparams_0' and the filter 'auto_scale_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
[aac @ 0x862899400] Qavg: 65536.000
[aac @ 0x862899400] 2 frames left in the queue on closing
Conversion failed!
One final thing to try:
pkg remove libva-intel-media-driver
pkg install libva-intel-driver
For that test, I encountered the following error message:
root@jellyfin:~ # vainfo
Trying display: wayland
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
Trying display: x11
error: can't connect to X server!
Trying display: drm
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/local/lib/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /usr/local/lib/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva error: /usr/local/lib/dri/i965_drv_video.so init failed
libva info: va_openDriver() returns -1
vaInitialize failed with error code -1 (unknown libva error),exit
and
[AVHWDeviceContext @ 0x85c9b11c0] libva: /usr/local/lib/dri/i965_drv_video.so init failed
[AVHWDeviceContext @ 0x85c9b11c0] Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
No device available for decoder: device type vaapi needed for codec hevc.
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_vaapi))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Device setup failed for decoder on input stream #0:0 : Input/output error
I believe there might be an issue with FFmpeg. Jellyfin provides a package called ffmpeg-jellyfin
, and I'm not sure how much it differs from the vanilla FFmpeg, but I'll need to research it. Have you had success with this process using any Intel iGPU?
@gmsotavio I don't have any hardware to test it on sadly. If you want to try a different (but not jellyfin's version) of FFmpeg, I make a static binary for it: https://github.com/Thefrank/ffmpeg-static-freebsd . I doubt it will work with hwaccel as that is very difficult to do via static linking
@Thefrank, I conducted some additional tests tonight. I attempted to isolate Jellyfin from FFmpeg. I took one of the movie files I was trying to play and manually performed an HEVC -> H.264 conversion using only FFmpeg with options for decoding using hwaccel@vaapi.
The command below worked:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.mkv -filter:v "scale_vaapi=w=3840:h=2160:format=nv12" -c:v h264_vaapi -profile:v main output.mkv
root@jellyfin:/tmp # ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.mkv -filter:v "scale_vaapi=w=3840:h=2160:format=nv12" -c:v h264_vaapi -profile:v main output.mkv
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
configuration: --prefix=/usr/local --mandir=/usr/local/man --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt --enable-shared --enable-pic --enable-gpl --cc=cc --cxx=c++ --disable-alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --enable-libaom --disable-libaribb24 --enable-asm --enable-libass --disable-libbs2b --disable-libcaca --disable-libcdio --disable-libcodec2 --enable-libdav1d --disable-libdavs2 --disable-libdc1394 --disable-debug --enable-htmlpages --enable-libdrm --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libfribidi --disable-gcrypt --disable-libglslang --disable-libgme --enable-gmp --enable-gnutls --enable-version3 --disable-libgsm --enable-iconv --disable-libilbc --disable-libjack --enable-libjxl --disable-libklvanc --disable-libkvazaar --disable-ladspa --enable-libmp3lame --enable-lcms2 --disable-liblensfun --disable-libbluray --enable-libplacebo --disable-librsvg --disable-librtmp --enable-libxml2 --disable-lto --disable-lv2 --disable-mbedtls --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-network --disable-nonfree --enable-nvenc --disable-openal --disable-opencl --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --disable-openssl --disable-libopenvino --enable-optimizations --enable-libopus --disable-pocketsphinx --disable-libpulse --disable-librabbitmq --disable-librav1e --disable-librist --enable-runtime-cpudetect --disable-librubberband --disable-sdl2 --enable-libshaderc --disable-libsmbclient --disable-libsnappy --disable-sndio --disable-libsoxr --disable-libspeex --disable-libsrt --disable-libssh --enable-libsvtav1 --disable-libtensorflow --disable-libtesseract --disable-libtheora --disable-libtwolame --disable-libuavs3d --enable-libv4l2 --enable-vaapi --disable-vapoursynth --enable-vdpau --disable-libvidstab --enable-libvmaf --enable-libvorbis --disable-libvo-amrwbenc --disable-libvpl --enable-libvpx --enable-vulkan --enable-libwebp --enable-libx264 --enable-libx265 --disable-libxavs2 --enable-libxcb --disable-libxvid --disable-outdev=xv --disable-libzimg --disable-libzmq --disable-libzvbi
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Input #0, matroska,webm, from 'input.mkv':
Metadata:
ENCODER : Lavf59.33.100
Duration: 02:17:53.18, start: -0.043000, bitrate: 6388 kb/s
Chapters:
Chapter #0:0: start 0.000000, end 9.000000
Chapter #0:1: start 9.000000, end 42.000000
Chapter #0:2: start 42.000000, end 132.000000
Chapter #0:3: start 132.000000, end 289.000000
Chapter #0:4: start 289.000000, end 297.000000
Chapter #0:5: start 297.000000, end 477.000000
Chapter #0:6: start 477.000000, end 525.000000
Chapter #0:7: start 525.000000, end 636.000000
Chapter #0:8: start 636.000000, end 750.000000
Chapter #0:9: start 750.000000, end 803.000000
Chapter #0:10: start 803.000000, end 831.000000
Chapter #0:11: start 831.000000, end 1029.000000
Chapter #0:12: start 1029.000000, end 1131.000000
Chapter #0:13: start 1131.000000, end 1253.000000
Chapter #0:14: start 1253.000000, end 1413.000000
Chapter #0:15: start 1413.000000, end 1807.000000
Chapter #0:16: start 1807.000000, end 1935.000000
Chapter #0:17: start 1935.000000, end 2081.000000
Chapter #0:18: start 2081.000000, end 2180.000000
Chapter #0:19: start 2180.000000, end 2255.000000
Chapter #0:20: start 2255.000000, end 2469.000000
Chapter #0:21: start 2469.000000, end 2571.000000
Chapter #0:22: start 2571.000000, end 2968.000000
Chapter #0:23: start 2968.000000, end 2998.000000
Chapter #0:24: start 2998.000000, end 3081.000000
Chapter #0:25: start 3081.000000, end 3117.000000
Chapter #0:26: start 3117.000000, end 3284.000000
Chapter #0:27: start 3284.000000, end 3430.000000
Chapter #0:28: start 3430.000000, end 3655.000000
Chapter #0:29: start 3655.000000, end 3817.000000
Chapter #0:30: start 3817.000000, end 3961.000000
Chapter #0:31: start 3961.000000, end 4142.000000
Chapter #0:32: start 4142.000000, end 4327.000000
Chapter #0:33: start 4327.000000, end 4923.000000
Chapter #0:34: start 4923.000000, end 5086.000000
Chapter #0:35: start 5086.000000, end 5267.000000
Chapter #0:36: start 5267.000000, end 5446.000000
Chapter #0:37: start 5446.000000, end 5551.000000
Chapter #0:38: start 5551.000000, end 5650.000000
Chapter #0:39: start 5650.000000, end 5745.000000
Chapter #0:40: start 5745.000000, end 5913.000000
Chapter #0:41: start 5913.000000, end 6162.000000
Chapter #0:42: start 6162.000000, end 6344.000000
Chapter #0:43: start 6344.000000, end 6966.000000
Chapter #0:44: start 6966.000000, end 7244.000000
Chapter #0:45: start 7244.000000, end 7327.000000
Chapter #0:46: start 7327.000000, end 7449.000000
Chapter #0:47: start 7449.000000, end 7496.000000
Chapter #0:48: start 7496.000000, end 7643.000000
Chapter #0:49: start 7643.000000, end 7764.000000
Chapter #0:50: start 7764.000000, end 7900.000000
Chapter #0:51: start 7900.000000, end 8273.152000
Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt709, progressive), 3658x2074 [SAR 1:1 DAR 1829:1037], 23.98 fps, 23.98 tbr, 1k tbn (default) (original)
Metadata:
ENCODER : Lavc59.48.100 libx265
DURATION : 02:17:52.640000000
Stream #0:1: Audio: aac (LC), 48000 Hz, 5.1, fltp (default) (original)
Metadata:
ENCODER : Lavc59.48.100 libfdk_aac
DURATION : 02:17:53.184000000
Stream #0:2(eng): Subtitle: subrip (default) (original)
Metadata:
DURATION : 02:10:31.323000000
Stream #0:3(eng): Subtitle: subrip (original) (hearing impaired)
Metadata:
title : SDH
DURATION : 02:10:31.323000000
Stream #0:4(ara): Subtitle: subrip
Metadata:
DURATION : 02:17:51.378000000
Stream #0:5(dan): Subtitle: subrip
Metadata:
DURATION : 02:17:51.462000000
Stream #0:6(ger): Subtitle: subrip
Metadata:
DURATION : 02:17:51.577000000
Stream #0:7(spa): Subtitle: subrip
Metadata:
DURATION : 02:13:02.971000000
Stream #0:8(spa): Subtitle: subrip
Metadata:
DURATION : 02:17:51.592000000
Stream #0:9(fin): Subtitle: subrip
Metadata:
DURATION : 02:17:51.637000000
Stream #0:10(fil): Subtitle: subrip
Metadata:
DURATION : 02:17:41.750000000
Stream #0:11(fre): Subtitle: subrip
Metadata:
DURATION : 02:17:51.542000000
Stream #0:12(hin): Subtitle: subrip
Metadata:
DURATION : 02:17:51.652000000
Stream #0:13(ita): Subtitle: subrip
Metadata:
DURATION : 02:17:51.584000000
Stream #0:14(jpn): Subtitle: subrip
Metadata:
DURATION : 02:10:31.329000000
Stream #0:15(kor): Subtitle: subrip
Metadata:
DURATION : 02:17:51.693000000
Stream #0:16(may): Subtitle: subrip
Metadata:
DURATION : 02:10:31.576000000
Stream #0:17(dut): Subtitle: subrip
Metadata:
DURATION : 02:17:51.612000000
Stream #0:18(nor): Subtitle: subrip
Metadata:
DURATION : 02:17:51.543000000
Stream #0:19(pol): Subtitle: subrip
Metadata:
DURATION : 02:17:51.577000000
Stream #0:20(por): Subtitle: subrip
Metadata:
DURATION : 02:13:02.993000000
Stream #0:21(por): Subtitle: subrip
Metadata:
DURATION : 02:17:51.533000000
Stream #0:22(rum): Subtitle: subrip
Metadata:
DURATION : 02:10:31.780000000
Stream #0:23(rus): Subtitle: subrip
Metadata:
DURATION : 02:17:51.615000000
Stream #0:24(swe): Subtitle: subrip
Metadata:
DURATION : 02:17:51.585000000
Stream #0:25(tur): Subtitle: subrip
Metadata:
DURATION : 02:17:51.519000000
Stream #0:26(chi): Subtitle: subrip
Metadata:
DURATION : 02:10:31.510000000
Stream #0:27(chi): Subtitle: subrip
Metadata:
DURATION : 02:17:51.767000000
File 'output.mkv' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (hevc (native) -> h264 (h264_vaapi))
Stream #0:1 -> #0:1 (aac (native) -> vorbis (libvorbis))
Stream #0:2 -> #0:2 (subrip (srt) -> ass (ssa))
Press [q] to stop, [?] for help
[h264_vaapi @ 0x85bf5d400] No quality level set; using default (20).
Output #0, matroska, to 'output.mkv':
Metadata:
encoder : Lavf60.3.100
Chapters:
Chapter #0:0: start 0.043000, end 9.043000
Chapter #0:1: start 9.043000, end 42.043000
Chapter #0:2: start 42.043000, end 132.043000
Chapter #0:3: start 132.043000, end 289.043000
Chapter #0:4: start 289.043000, end 297.043000
Chapter #0:5: start 297.043000, end 477.043000
Chapter #0:6: start 477.043000, end 525.043000
Chapter #0:7: start 525.043000, end 636.043000
Chapter #0:8: start 636.043000, end 750.043000
Chapter #0:9: start 750.043000, end 803.043000
Chapter #0:10: start 803.043000, end 831.043000
Chapter #0:11: start 831.043000, end 1029.043000
Chapter #0:12: start 1029.043000, end 1131.043000
Chapter #0:13: start 1131.043000, end 1253.043000
Chapter #0:14: start 1253.043000, end 1413.043000
Chapter #0:15: start 1413.043000, end 1807.043000
Chapter #0:16: start 1807.043000, end 1935.043000
Chapter #0:17: start 1935.043000, end 2081.043000
Chapter #0:18: start 2081.043000, end 2180.043000
Chapter #0:19: start 2180.043000, end 2255.043000
Chapter #0:20: start 2255.043000, end 2469.043000
Chapter #0:21: start 2469.043000, end 2571.043000
Chapter #0:22: start 2571.043000, end 2968.043000
Chapter #0:23: start 2968.043000, end 2998.043000
Chapter #0:24: start 2998.043000, end 3081.043000
Chapter #0:25: start 3081.043000, end 3117.043000
Chapter #0:26: start 3117.043000, end 3284.043000
Chapter #0:27: start 3284.043000, end 3430.043000
Chapter #0:28: start 3430.043000, end 3655.043000
Chapter #0:29: start 3655.043000, end 3817.043000
Chapter #0:30: start 3817.043000, end 3961.043000
Chapter #0:31: start 3961.043000, end 4142.043000
Chapter #0:32: start 4142.043000, end 4327.043000
Chapter #0:33: start 4327.043000, end 4923.043000
Chapter #0:34: start 4923.043000, end 5086.043000
Chapter #0:35: start 5086.043000, end 5267.043000
Chapter #0:36: start 5267.043000, end 5446.043000
Chapter #0:37: start 5446.043000, end 5551.043000
Chapter #0:38: start 5551.043000, end 5650.043000
Chapter #0:39: start 5650.043000, end 5745.043000
Chapter #0:40: start 5745.043000, end 5913.043000
Chapter #0:41: start 5913.043000, end 6162.043000
Chapter #0:42: start 6162.043000, end 6344.043000
Chapter #0:43: start 6344.043000, end 6966.043000
Chapter #0:44: start 6966.043000, end 7244.043000
Chapter #0:45: start 7244.043000, end 7327.043000
Chapter #0:46: start 7327.043000, end 7449.043000
Chapter #0:47: start 7449.043000, end 7496.043000
Chapter #0:48: start 7496.043000, end 7643.043000
Chapter #0:49: start 7643.043000, end 7764.043000
Chapter #0:50: start 7764.043000, end 7900.043000
Chapter #0:51: start 7900.043000, end 8273.195000
Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), vaapi(tv, bt709, progressive), 3840x2160 [SAR 16461:16592 DAR 1829:1037], q=2-31, 23.98 fps, 1k tbn (default) (original)
Metadata:
DURATION : 02:17:52.640000000
encoder : Lavc60.3.100 h264_vaapi
Stream #0:1: Audio: vorbis (oV[0][0] / 0x566F), 48000 Hz, 5.1, fltp (default) (original)
Metadata:
DURATION : 02:17:53.184000000
encoder : Lavc60.3.100 libvorbis
Stream #0:2(eng): Subtitle: ass (default) (original)
Metadata:
DURATION : 02:10:31.323000000
encoder : Lavc60.3.100 ssa
[libvorbis @ 0x85bf5dc00] Queue input is backward in time60 bitrate= 6.1kbits/s speed=2.96x
frame= 364 fps= 67 q=-0.0 Lsize= 23179kB time=00:00:15.56 bitrate=12199.1kbits/s speed=2.88x
As you can see in the image, the processor load is very low during the transcode, confirming the use of the iGPU:
Possibly, some of the filter parameters passed by Jellyfin are causing the issue. The thing is, it's not about problems with drivers or even issues with FFmpeg. Everything should be working. I'll be investigating further the parameters that Jellyfin passes to FFmpeg.
For instance, if I attempt to remove the parameter -filter:v "scale_vaapi=w=3840:h=2160:format=nv12"
from the command mentioned above, the conversion will fail. So, a minor change in the filter parameters can lead to a total transcoding failure.
As we can see in the Jellyfin command issued to FFmepg, the filter selection is a bit complex and harder to grasp:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -analyzeduration 200M -i "file:/mnt/downloads/Noah (2014) [2160p] [4K] [WEB] [5.1] [YTS.MX]/Noah.2014.2160p.4K.WEB.x265.10bit.AAC5.1-[YTS.MX].mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_vaapi -rc_mode VBR -b:v 6388419 -maxrate 6388419 -bufsize 12776838 -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale=trunc(min(max(iw\,ih*a)\,min(3658\,2074*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(3658/a\,2074))/2)*2,format=nv12,hwupload=derive_device=vaapi" -codec:a:0 aac -ac 2 -ab 384000 -ar 48000 -af "volume=2" -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "/var/db/jellyfin/transcodes/6165c611a2803daab963a55b0fe28af3%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "/var/db/jellyfin/transcodes/6165c611a2803daab963a55b0fe28af3.m3u8"
For now, I appreciate the help and time dedicated to assist me.
@Thefrank I managed to make it work (manually). I'm almost there.
Params that Jellyfin passes to lffmpeg:
-analyzeduration 200M -i "file:/mnt/downloads/Noah (2014) [2160p] [4K] [WEB] [5.1] [YTS.MX]/Noah.2014.2160p.4K.WEB.x265.10bit.AAC5.1-[YTS.MX].mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_vaapi -rc_mode VBR -b:v 6388419 -maxrate 6388419 -bufsize 12776838 -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale=trunc(min(max(iw\,ih*a)\,min(3658\,2074*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(3658/a\,2074))/2)*2,format=nv12,hwupload=derive_device=vaapi" -codec:a:0 aac -ac 2 -ab 384000 -ar 48000 -af "volume=2" -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "/var/db/jellyfin/transcodes/6165c611a2803daab963a55b0fe28af3%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "/var/db/jellyfin/transcodes/6165c611a2803daab963a55b0fe28af3.m3u8"
After making several modifications, the results are as follows:
-analyzeduration 200M -i "file:/mnt/downloads/Noah (2014) [2160p] [4K] [WEB] [5.1] [YTS.MX]/Noah.2014.2160p.4K.WEB.x265.10bit.AAC5.1-[YTS.MX].mkv" -map_metadata -1 -map_chapters -1 -threads 8 -map 0:0 -map 0:1 -map -0:s -codec:v:0 h264_vaapi -rc_mode VBR -b:v 6388419 -maxrate 6388419 -bufsize 12776838 -force_key_frames:0 "expr:gte(t,0+n_forced*3)" -vf "setparams=color_primaries=bt709:color_trc=bt709:colorspace=bt709,scale_vaapi=trunc(min(max(iw\,ih*a)\,min(3658\,2074*a))/2)*2:trunc(min(max(iw/a\,ih)\,min(3658/a\,2074))/2)*2:format=nv12" -codec:a:0 aac -ac 2 -ab 384000 -ar 48000 -af "volume=2" -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 3 -hls_segment_type mpegts -start_number 0 -hls_segment_filename "/var/db/jellyfin/transcodes/6165c611a2803daab963a55b0fe28af3%d.ts" -hls_playlist_type vod -hls_list_size 0 -y "/var/db/jellyfin/transcodes/6165c611a2803daab963a55b0fe28af3.m3u8"
Et voilà!
What I have changed
Aditionally, It will be necessary to add -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -analyzeduration
to lffmpeg:
# cat /usr/local/bin/lffmpeg
#!/bin/sh
echo "$@" > /tmp/params
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi "$@"
Now, I need to find a way to modify the parameters passed to lffmpeg before they are fed to the ffmpeg executable. I'm unsure if this is possible.
If jellyfin assumes that you are using FFmpeg v5 instead of v6 it might explain some of the args being passed oddly. The API between 4->5->6 are all slightly different
Hi @gmsotavio, currently having the same problem with the same hardware. Where you able to find a fix and make transcoding work?
Hello @johndodigie,
I am still investigating the cause of the problem. Here are some clarifications:
My two assumptions when analyzing the Jellyfin source code are:
Currently, I am using software transcoding, but I would very much like to enable hardware transcoding, as I have already proven that it works perfectly in FreeBSD jails and would significantly alleviate the load on my processor.
I should have some free time after the holidays to deep-dive this issue. A quick glance seems to point at requiring some source changes to support VAAPI. As pointed out, it already does a good job of determine which version of FFmpeg is being used; it should be able to use .git
builds or even builds with mangled versions.
This (hopefully) is just an ||
away from working. dotNET has understood what OperatingSystem.IsFreeBSD()
is since NET5 https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isfreebsd?view=net-8.0 and OSPlatform.FreeBSD
since Core 3.0 https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.osplatform.freebsd?view=net-8.0
@gmsotavio
https://github.com/Thefrank/jellyfin-server-freebsd/releases/tag/jellyfin-vaapi-test
Let me know if that resolves the issue. If it does, I will work on QSV next.
@Thefrank
Thank you for sharing. I'll test your modifications and promptly share the results with you. I appreciate the efforts you've put into assisting us with this.
@Thefrank
In the tests I conducted, I did not notice any difference. The parameters that Jellyfin passes to ffmpeg are exactly the same. I really don't know if I might be doing something wrong.
However, upon reviewing the code again, I came across this:
var isVaapiFullSupported = isLinux && IsVaapiSupported(state) && IsVaapiFullSupported();
It seems that Vaapi is only considered fully supported if the system is Linux. I don't know if this could be influencing the issue we are facing.
var isLinux = OperatingSystem.IsLinux();
Note that the hardware image scaling filter scale_vaapi
is only enabled if IsVaapiFullSupported
. Otherwise, only scale
will be passed to ffmpeg instead of scale_vaapi
.
private bool IsVaapiFullSupported()
{
return _mediaEncoder.SupportsHwaccel("drm")
&& _mediaEncoder.SupportsHwaccel("vaapi")
&& _mediaEncoder.SupportsFilter("scale_vaapi")
&& _mediaEncoder.SupportsFilter("deinterlace_vaapi")
&& _mediaEncoder.SupportsFilter("tonemap_vaapi")
&& _mediaEncoder.SupportsFilter("procamp_vaapi")
&& _mediaEncoder.SupportsFilterWithOption(FilterOptionType.OverlayVaapiFrameSync)
&& _mediaEncoder.SupportsFilter("hwupload_vaapi");
}
Note that these are just observations. I do not know if this is the root of the problem, but they might indicate a potential issue. I am not an expert in drm, ffmpeg, or related subjects.
@gmsotavio The changes I tried were to add OperatingSystem.IsFreeBSD()
to the OS checks under the VAAPI support checks and to create and use a isFreeBSD
to be added to cases where that is used over the OperatingSystem
call. This should have been enough but clearly was not :(
If the Jellyfin version of FFmpeg has additonal filters, it might be why the checks are also failing but looking at the configure for FFmpeg 6.1 all of the same filters and filter options appear in it that jellyfin tries to find. Other media players on FreeBSD use VAAPI and/or QSV without issue. This is something very specific to Jellyfin that I missing.
I should have some more time over the weekend to dig into this.
Did you get any further with this, I'm pretty keen to get this working
Did you get any further with this, I'm pretty keen to get this working
I rebuild the server and web parts with some more patching if you want to try it: https://github.com/Thefrank/jellyfin-server-freebsd/releases/tag/jellyfin-vaapi-test
unfortunately it didn't work
from the logs it seems to have decided not to enable hardware acceleration
ffmpeg -analyzeduration 200M -probesize 1G -fflags +genpts -i file:"/mnt/movies/REDACTED.mkv" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:1 -map 0:0 -map -0:s -codec:v:0 copy -bsf:v h264_mp4toannexb -start_at_zero -codec:a:0 aac -ac 2 -ab 384000 -af "volume=2" -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 6 -hls_segment_type fmp4 -hls_fmp4_init_filename "ae85d71fca545860cfb3aa43da9aa0fd-1.mp4" -start_number 0 -hls_segment_filename "/var/db/jellyfin/transcodes/ae85d71fca545860cfb3aa43da9aa0fd%d.mp4" -hls_playlist_type vod -hls_list_size 0 -y "/var/db/jellyfin/transcodes/ae85d71fca545860cfb3aa43da9aa0fd.m3u8"
ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
built with FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)
configuration: --prefix=/usr/local --mandir=/usr/local/share/man --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt --enable-shared --enable-pic --enable-gpl --cc=cc --cxx=c++ --disable-alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --enable-libaom --disable-libaribb24 --disable-libaribcaption --enable-asm --enable-libass --disable-libbs2b --disable-libcaca --disable-libcdio --disable-libcodec2 --enable-libdav1d --disable-libdavs2 --disable-libdc1394 --disable-debug --enable-htmlpages --enable-libdrm --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libfribidi --disable-gcrypt --disable-libglslang --disable-libgme --enable-gmp --enable-gnutls --enable-version3 --disable-libgsm --enable-libharfbuzz --enable-iconv --disable-libilbc --disable-libjack --enable-libjxl --disable-libklvanc --disable-libkvazaar --disable-ladspa --enable-libmp3lame --enable-lcms2 --disable-liblensfun --disable-libbluray --enable-libplacebo --disable-librsvg --disable-librtmp --enable-libxml2 --disable-lv2 --disable-mbedtls --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-network --disable-nonfree --enable-nvenc --disable-openal --disable-opencl --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --disable-openssl --disable-libopenvino --enable-optimizations --enable-libopus --disable-pocketsphinx --disable-libpulse --disable-librabbitmq --disable-librav1e --disable-librist --enable-runtime-cpudetect --disable-librubberband --disable-sdl2 --enable-libshaderc --disable-libsmbclient --disable-libsnappy --disable-sndio --disable-libsoxr --disable-libspeex --disable-libsrt --disable-libssh --enable-libsvtav1 --disable-libtensorflow --disable-libtesseract --disable-libtheora --disable-libtwolame --disable-libuavs3d --enable-libv4l2 --enable-vaapi --disable-vapoursynth --enable-vdpau --disable-libvidstab --enable-libvmaf --enable-libvorbis --disable-libvo-amrwbenc --disable-libvpl --enable-libvpx --enable-vulkan --enable-libwebp --enable-libx264 --enable-libx265 --disable-libxavs2 --enable-libxcb --disable-libxvid --disable-outdev=xv --disable-libzimg --disable-libzmq --disable-libzvbi
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
Input #0, matroska,webm, from 'file:/mnt/movies/REDACTED.mkv':
Metadata:
title : EVO
encoder : libebml v1.3.0 + libmatroska v1.4.1
creation_time : 2020-03-09T14:10:26.000000Z
Duration: 01:58:58.62, start: 0.000000, bitrate: 4793 kb/s
Chapters:
Chapter #0:0: start 0.000000, end 300.342000
Metadata:
title : 1
Chapter #0:1: start 300.342000, end 500.333000
Metadata:
title : 2
Chapter #0:2: start 500.333000, end 807.556000
Metadata:
title : 3
Chapter #0:3: start 807.556000, end 999.705000
Metadata:
title : 4
Chapter #0:4: start 999.705000, end 1414.493000
Metadata:
title : 5
Chapter #0:5: start 1414.493000, end 1829.574000
Metadata:
title : 6
Chapter #0:6: start 1829.574000, end 2136.546000
Metadata:
title : 7
Chapter #0:7: start 2136.546000, end 2546.288000
Metadata:
title : 8
Chapter #0:8: start 2546.288000, end 3095.003000
Metadata:
title : 9
Chapter #0:9: start 3095.003000, end 3397.220000
Metadata:
title : 10
Chapter #0:10: start 3397.220000, end 3749.988000
Metadata:
title : 11
Chapter #0:11: start 3749.988000, end 3994.524000
Metadata:
title : 12
Chapter #0:12: start 3994.524000, end 4325.228000
Metadata:
title : 13
Chapter #0:13: start 4325.228000, end 4786.355000
Metadata:
title : 14
Chapter #0:14: start 4786.355000, end 5328.730000
Metadata:
title : 15
Chapter #0:15: start 5328.730000, end 5624.357000
Metadata:
title : 16
Chapter #0:16: start 5624.357000, end 5892.500000
Metadata:
title : 17
Chapter #0:17: start 5892.500000, end 6104.586000
Metadata:
title : 18
Chapter #0:18: start 6104.586000, end 6568.216000
Metadata:
title : 19
Chapter #0:19: start 6568.216000, end 7138.624000
Metadata:
title : 20
Stream #0:0(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s (default)
Stream #0:1(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x798 [SAR 1:1 DAR 320:133], 23.98 fps, 23.98 tbr, 1k tbn (default)
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Stream #0:0 -> #0:1 (ac3 (native) -> aac (native))
Press [q] to stop, [?] for help
[hls @ 0x14615e831500] Opening '/var/db/jellyfin/transcodes/ae85d71fca545860cfb3aa43da9aa0fd-1.mp4' for writing
Output #0, hls, to '/var/db/jellyfin/transcodes/ae85d71fca545860cfb3aa43da9aa0fd.m3u8':
Metadata:
encoder : Lavf60.16.100
Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x798 [SAR 1:1 DAR 320:133], q=2-31, 23.98 fps, 23.98 tbr, 16k tbn (default)
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 384 kb/s (default)
Metadata:
encoder : Lavc60.31.102 aac
That looks like it is not even trying to make any hw decoding.
I do not have any hardware that does hardware acceleration so it is rather hard to debug what it is seeing.
does ffmpeg
correctly use hardware when run manually? Is this setup correctly in jellyfin either through the UI or the config file?
what does your startup look like? Here is mine where it just tests the results of -hwaccels
. -filters
, and the like
04:34:15] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Found ffmpeg version 6.1.1
[04:34:15] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available decoders: ["libdav1d", "av1", "av1_cuvid", "h264", "h264_cuvid", "hevc", "hevc_cuvid", "mpeg2video", "mpeg2_cuvid", "mpeg4", "mpeg4_cuvid", "msmpeg4", "vc1_cuvid", "vp8", "libvpx", "vp8_cuvid", "vp9", "libvpx-vp9", "vp9_cuvid", "aac", "ac3", "dca", "flac", "mp3", "truehd"]
[04:34:15] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available encoders: ["libsvtav1", "av1_nvenc", "av1_vaapi", "libx264", "h264_nvenc", "h264_v4l2m2m", "h264_vaapi", "libx265", "hevc_nvenc", "hevc_vaapi", "mpeg4", "msmpeg4", "libvpx", "libvpx-vp9", "aac", "ac3", "dca", "flac", "libmp3lame", "libopus", "truehd", "libvorbis", "srt"]
[04:34:15] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available filters: ["deinterlace_vaapi", "hwupload_cuda", "libplacebo", "overlay_vaapi", "overlay_vulkan", "procamp_vaapi", "scale_vaapi", "scale_vulkan", "tonemap_vaapi"]
[04:34:15] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: scale_cuda with option Output format (default "same") is not available
[04:34:15] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: tonemap_cuda with option GPU accelerated HDR to SDR tonemapping is not available
[04:34:15] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: tonemap_opencl with option bt2390 is not available
[04:34:15] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: overlay_opencl with option Action to take when encountering EOF from secondary input is not available
[04:34:15] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available hwaccel types: ["vdpau", "cuda", "vaapi", "drm", "vulkan"]
[04:34:15] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: FFmpeg: ffmpeg
pinging @gmsotavio if you are still around and want to try another build
[2024-04-06 09:13:28.860 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Found ffmpeg version "6.1.1"
[2024-04-06 09:13:28.894 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available "decoders": ["libdav1d", "av1", "av1_cuvid", "h264", "h264_cuvid", "hevc", "hevc_cuvid", "mpeg2video", "mpeg2_cuvid", "mpeg4", "mpeg4_cuvid", "msmpeg4", "vc1_cuvid", "vp8", "libvpx", "vp8_cuvid", "vp9", "libvpx-vp9", "vp9_cuvid", "aac", "ac3", "dca", "flac", "mp3", "truehd"]
[2024-04-06 09:13:28.919 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available "encoders": ["libsvtav1", "av1_nvenc", "av1_vaapi", "libx264", "h264_nvenc", "h264_v4l2m2m", "h264_vaapi", "libx265", "hevc_nvenc", "hevc_vaapi", "mpeg4", "msmpeg4", "libvpx", "libvpx-vp9", "aac", "ac3", "dca", "flac", "libmp3lame", "libopus", "truehd", "libvorbis", "srt"]
[2024-04-06 09:13:29.002 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available filters: ["deinterlace_vaapi", "hwupload_cuda", "libplacebo", "overlay_vaapi", "overlay_vulkan", "procamp_vaapi", "scale_vaapi", "scale_vulkan", "tonemap_vaapi"]
[2024-04-06 09:13:29.072 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "scale_cuda" with option "Output format (default \"same\")" is not available
[2024-04-06 09:13:29.096 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "tonemap_cuda" with option "GPU accelerated HDR to SDR tonemapping" is not available
[2024-04-06 09:13:29.117 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "tonemap_opencl" with option "bt2390" is not available
[2024-04-06 09:13:29.139 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "overlay_opencl" with option "Action to take when encountering EOF from secondary input" is not available
[2024-04-06 09:13:29.268 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available hwaccel types: ["vdpau", "cuda", "vaapi", "drm", "vulkan"]
[2024-04-06 09:13:29.640 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: VAAPI device "/dev/dri/renderD128" is Intel GPU (i965)
[2024-04-06 09:13:29.640 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: FFmpeg: "ffmpeg"
[2024-04-06 09:13:29.641 +08:00] [INF] [1] Emby.Server.Implementations.ApplicationHost: ServerId: "ca427d64187040b080e5ee3edfeddf79"
[2024-04-06 09:13:29.641 +08:00] [INF] [1] Emby.Server.Implementations.ApplicationHost: Core startup complete
[2024-04-06 09:13:29.641 +08:00] [INF] [1] Main: Startup complete 0:00:12.8292809
[2024-04-06 09:13:31.682 +08:00] [INF] [8] Emby.Server.Implementations.ScheduledTasks.TaskManager: "Clean up collections and playlists" Completed after 0 minute(s) and 0 seconds
[2024-04-06 09:13:31.826 +08:00] [ERR] [8] Emby.Server.Implementations.Updates.InstallationManager: An error occurred while accessing the plugin manifest: "https://repo.jellyfin.org/files/plugin/manifest.json"
System.Net.Http.HttpRequestException: Name does not resolve (repo.jellyfin.org:443)
i wonder if my issue is the plugin repo not resolving - which is weird, the jail has raw sockets turned on and has perfectly working network otherwise.
i've also been trying to get opencl working to eliminate that, although i have tone mapping turned off so it shouldn't need it. I can't figure out why opencl doesn't want to work (even outside the jail)
# ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128 -init_hw_device opencl
ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
built with FreeBSD clang version 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1a259152)
configuration: --prefix=/usr/local --mandir=/usr/local/share/man --datadir=/usr/local/share/ffmpeg --docdir=/usr/local/share/doc/ffmpeg --pkgconfigdir=/usr/local/libdata/pkgconfig --disable-static --disable-libcelt --enable-shared --enable-pic --enable-gpl --cc=cc --cxx=c++ --disable-alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --enable-libaom --disable-libaribb24 --disable-libaribcaption --enable-asm --enable-libass --disable-libbs2b --disable-libcaca --disable-libcdio --disable-libcodec2 --enable-libdav1d --disable-libdavs2 --disable-libdc1394 --disable-debug --enable-htmlpages --enable-libdrm --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libfribidi --disable-gcrypt --disable-libglslang --disable-libgme --enable-gmp --enable-gnutls --enable-version3 --disable-libgsm --enable-libharfbuzz --enable-iconv --disable-libilbc --disable-libjack --enable-libjxl --disable-libklvanc --disable-libkvazaar --disable-ladspa --enable-libmp3lame --enable-lcms2 --disable-liblensfun --disable-libbluray --enable-libplacebo --disable-librsvg --disable-librtmp --enable-libxml2 --disable-lv2 --disable-mbedtls --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-network --disable-nonfree --enable-nvenc --disable-openal --disable-opencl --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --disable-openssl --disable-libopenvino --enable-optimizations --enable-libopus --disable-pocketsphinx --disable-libpulse --disable-librabbitmq --disable-librav1e --disable-librist --enable-runtime-cpudetect --disable-librubberband --disable-sdl2 --enable-libshaderc --disable-libsmbclient --disable-libsnappy --disable-sndio --disable-libsoxr --disable-libspeex --disable-libsrt --disable-libssh --enable-libsvtav1 --disable-libtensorflow --disable-libtesseract --disable-libtheora --disable-libtwolame --disable-libuavs3d --enable-libv4l2 --enable-vaapi --disable-vapoursynth --enable-vdpau --disable-libvidstab --enable-libvmaf --enable-libvorbis --disable-libvo-amrwbenc --disable-libvpl --enable-libvpx --enable-vulkan --enable-libwebp --enable-libx264 --enable-libx265 --disable-libxavs2 --enable-libxcb --disable-libxvid --disable-outdev=xv --disable-libzimg --disable-libzmq --disable-libzvbi
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
[AVHWDeviceContext @ 0x73855619100] libva: VA-API version 1.20.0
[AVHWDeviceContext @ 0x73855619100] libva: Trying to open /usr/local/lib/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x73855619100] libva: va_openDriver() returns -1
[AVHWDeviceContext @ 0x73855619100] libva: Trying to open /usr/local/lib/dri/i965_drv_video.so
[AVHWDeviceContext @ 0x73855619100] libva: Found init function __vaDriverInit_1_20
[AVHWDeviceContext @ 0x73855619100] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x73855619100] Initialised VAAPI connection: version 1.20
[AVHWDeviceContext @ 0x73855619100] VAAPI driver: Intel i965 driver for Intel(R) Coffee Lake - 2.4.1.
[AVHWDeviceContext @ 0x73855619100] Driver not found in known nonstandard list, using standard behaviour.
Device creation failed: -12.
Failed to set value 'opencl' for option 'init_hw_device': Cannot allocate memory
Error parsing global options: Cannot allocate memory
host resolves fine inside the jail -
# ping repo.jellyfin.org
PING elb1.jellyfin.org (68.183.204.194): 56 data bytes
64 bytes from 68.183.204.194: icmp_seq=0 ttl=49 time=261.937 ms
64 bytes from 68.183.204.194: icmp_seq=1 ttl=49 time=260.705 ms
@rbev DNS name resolution errors (and some other network errors) can be caused by jellyfin's library monitoring. Try turning that off
The good news is that jellyfin DOES see a valid VAAPI device so it should be able to use it as a VAAPI device. Same with ffmpeg it does appear to see a VAAPI device. Neither jellyfin nor ffmpeg see a valid opencl device :(
Yeah i posted some logs on the freebsd forums puzzled about why i couldn't get opencl working on this igpu. I'd have to look at jellyfin's code but from what i can tell you don't need that working to use transcoding with VAAPI, only if you need to do tone mapping (which i've turned off)
In case it helps - here's my transcoding settings:
I did another restart and it looks like i get a clean startup now
[2024-04-06 13:53:50.894 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Found ffmpeg version "6.1.1"
[2024-04-06 13:53:50.927 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available "decoders": ["libdav1d", "av1", "av1_cuvid", "h264", "h264_cuvid", "hevc", "hevc_cuvid", "mpeg2video", "mpeg2_cuvid", "mpeg4", "mpeg4_cuvid", "msmpeg4", "vc1_cuvid", "vp8", "libvpx", "vp8_cuvid", "vp9", "libvpx-vp9", "vp9_cuvid", "aac", "ac3", "dca", "flac", "mp3", "truehd"]
[2024-04-06 13:53:50.949 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available "encoders": ["libsvtav1", "av1_nvenc", "av1_vaapi", "libx264", "h264_nvenc", "h264_v4l2m2m", "h264_vaapi", "libx265", "hevc_nvenc", "hevc_vaapi", "mpeg4", "msmpeg4", "libvpx", "libvpx-vp9", "aac", "ac3", "dca", "flac", "libmp3lame", "libopus", "truehd", "libvorbis", "srt"]
[2024-04-06 13:53:50.984 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available filters: ["deinterlace_vaapi", "hwupload_cuda", "libplacebo", "overlay_vaapi", "overlay_vulkan", "procamp_vaapi", "scale_vaapi", "scale_vulkan", "tonemap_vaapi"]
[2024-04-06 13:53:51.006 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "scale_cuda" with option "Output format (default \"same\")" is not available
[2024-04-06 13:53:51.026 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "tonemap_cuda" with option "GPU accelerated HDR to SDR tonemapping" is not available
[2024-04-06 13:53:51.045 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "tonemap_opencl" with option "bt2390" is not available
[2024-04-06 13:53:51.064 +08:00] [WRN] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Filter: "overlay_opencl" with option "Action to take when encountering EOF from secondary input" is not available
[2024-04-06 13:53:51.123 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available hwaccel types: ["vdpau", "cuda", "vaapi", "drm", "vulkan"]
[2024-04-06 13:53:51.511 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: VAAPI device "/dev/dri/renderD128" is Intel GPU (i965)
[2024-04-06 13:53:51.511 +08:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: FFmpeg: "ffmpeg"
[2024-04-06 13:53:51.513 +08:00] [INF] [1] Emby.Server.Implementations.ApplicationHost: ServerId: "ca427d64187040b080e5ee3edfeddf79"
[2024-04-06 13:53:51.513 +08:00] [INF] [1] Emby.Server.Implementations.ApplicationHost: Core startup complete
[2024-04-06 13:53:51.514 +08:00] [INF] [1] Main: Startup complete 0:00:05.0078485
[2024-04-06 13:53:53.890 +08:00] [INF] [10] Emby.Server.Implementations.ScheduledTasks.TaskManager: "Clean up collections and playlists" Completed after 0 minute(s) and 0 seconds
[2024-04-06 13:53:55.244 +08:00] [INF] [16] Emby.Server.Implementations.ScheduledTasks.TaskManager: "Update Plugins" Completed after 0 minute(s) and 1 seconds
[2024-04-06 13:53:56.151 +08:00] [INF] [18] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.168.1.1" request
no plugin errors - but still not hwaccel
Hrm. I have no idea why it does not even bother to use hwaccel despite detecting it.
For your opencl try ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128 -init_hw_device opencl@va
Same as above, vaapi works fine and then it prints this error for opencl:
Device creation failed: -12.
Failed to set value 'opencl@va' for option 'init_hw_device': Cannot allocate memory
Error parsing global options: Cannot allocate memory
and its the same thing outside the jail running as root
$ clinfo
Number of platforms 0
ICD loader properties
ICD loader Name OpenCL ICD Loader
ICD loader Vendor OCL Icd free software
ICD loader Version 2.3.1
ICD loader Profile OpenCL 3.0
clinfo does not even see the device so things like ffmpeg and jellyfin wont see it either. Does jellyfin try to use VAAPI at all in the logs? I am confused why it does not even try to use vaapi
I see absolutely nothing in the logs about it attempting to use vaapi - it seems like it's deciding it can't use it.
[2024-04-06 13:56:34.093 +08:00] [INF] [3] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.168.1.1" request
[2024-04-06 13:56:35.786 +08:00] [INF] [25] Jellyfin.Api.Helpers.MediaInfoHelper: User policy for "REDACTED". EnablePlaybackRemuxing: True EnableVideoPlaybackTranscoding: True EnableAudioPlaybackTranscoding: True
[2024-04-06 13:56:36.355 +08:00] [INF] [3] Jellyfin.Api.Controllers.DynamicHlsController: Current HLS implementation doesn't support non-keyframe breaks but one is requested, ignoring that request
[2024-04-06 13:56:36.366 +08:00] [INF] [3] MediaBrowser.MediaEncoding.Transcoding.TranscodeManager: "ffmpeg" "-analyzeduration 200M -probesize 1G -fflags +genpts -i file:\"/mnt/movies/REDACTED.mkv\" -map_metadata -1 -map_chapters -1 -threads 0 -map 0:1 -map 0:0 -map -0:s -codec:v:0 copy -bsf:v h264_mp4toannexb -start_at_zero -codec:a:0 aac -ac 2 -ab 384000 -af \"volume=2\" -copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 -f hls -max_delay 5000000 -hls_time 6 -hls_segment_type fmp4 -hls_fmp4_init_filename \"7ef1ddf23b364357d8dd1b54a07d2bb5-1.mp4\" -start_number 0 -hls_segment_filename \"/var/db/jellyfin/transcodes/7ef1ddf23b364357d8dd1b54a07d2bb5%d.mp4\" -hls_playlist_type vod -hls_list_size 0 -y \"/var/db/jellyfin/transcodes/7ef1ddf23b364357d8dd1b54a07d2bb5.m3u8\""
[2024-04-06 13:56:43.828 +08:00] [INF] [3] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.168.1.1" closed
[2024-04-06 13:56:44.464 +08:00] [INF] [3] Emby.Server.Implementations.HttpServer.WebSocketManager: WS "192.168.1.1" request
[2024-04-06 13:56:47.815 +08:00] [INF] [23] MediaBrowser.Controller.MediaEncoding.TranscodingJob: Stopping ffmpeg process with q command for "/var/db/jellyfin/transcodes/
and the transcode logs don't mention the drm device or vaapi outside of the printout of compile flags on startup (which i've pasted previously)
i can probably enable debug logging and restart - let me look up how to do that
edit: nothing enlightening in the debug logs
Doing some more reading of the jellyfin code it looks like the lack of openCL is my problem
from what i can tell here it falls back to a software decoding path unconditionally if there is no openCL available, and it's not doing the extra branch on line on 4425 to add the hardware encode to the end of it.
I'll spend some more time working out why opencl isn't working for me
I've started to lose hope -
I've narrowed my OpenCL issue down to this: https://github.com/FreeBSDDesktop/kms-drm/issues/197 which appears to be a problem I can't fix myself
Try Rusticl instead as described in https://github.com/freebsd/freebsd-ports/commit/d8990eff958b
$ pkg install mesa-devel
$ export RUSTICL_ENABLE=iris
$ clinfo
ok, that fixes clinfo but it doesn't change ffmpeg's behaviour it's at least something to move forward on
I think there is a typo in the jellyfin.diff patch that is preventing hardware acceleration from being detected properly.
When Jellyfin checks if the operating system is Linux, it uses if(isLinux)
for the positive case and if(!isLinux)
for the negative case. When the patch adds FreeBSD to these checks, it uses if(isLinux || isFreeBSD)
for the positive case which is correct, but uses if(!isLinux || !isFreeBSD)
which is is incorrect.
Rephrasing this using De Morgan's (https://en.wikipedia.org/wiki/De_Morgan%27s_laws), This statement becomes if(!(isLinux && isFreeBSD)
, which is much easier to see the issues as the operating system can't be Linux and FreeBSD at the same time, resulting in the inner statement always being false, causing this if statement to always be taken. This causes the VAAPI checks to always return false and prevents the required flags being added to the FFMPEG command.
To fix this, The patch lines containing if(!isLinux || !isFreeBSD)
should be converted to if(!(isLinux || isFreeBSD))
, which will return true only if the OS isn't Linux or FreeBSD, which I believe is the intended behaviour of this patch.
For the patch file itself, line 17 adds +if ((!isLinux || !isFreeBSD) || !_mediaEncoder.SupportsHwaccel("vaapi"))
and line 50 adds if ((!OperatingSystem.IsLinux() || !OperatingSystem.IsFreeBSD())
to MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs. Similarly, line 63if (!OperatingSystem.IsLinux() || !OperatingSystem.IsFreeBSD())
to MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs.
I don't have time to build the code with the fixes myself but I believe this should be enough to get VAAPI working.
@MACVTi good catch!
that diff is a bit out of date and does contain that logic flaw. The newest experimental binaries from ~2wk ago should have corrected logic.
Back in college I took a whole course on logic so it is rather embarrassing that it happened in the first place >.<
edit:
but yes ¬ ( a ∧ b ∧ c ) ∨ ¬ d
is easier to parse by humans than ( ¬ a ∧ ¬ b ∧ ¬ c ) ∨ ¬ d
Don't worry, I had to do some googling to remember it too! 😄
I'm only after seeing the VAAPI test release there now after you mentioned that test build in your previous comment. I've tested it on my computer and I can confirm that VAAPI is working for my AMD Raven Ridge GPU (Integrated graphics on AMD 3200G) on FreeBSD 14 with drm-515-kmod and the Mesa Gallium driver 24.0.4. The device is also correctly detected in the logs.
[2024-04-23 10:44:12.345 +01:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: Available hwaccel types: ["vdpau", "cuda", "vaapi", "drm", "vulkan"]
[2024-04-23 10:44:13.151 +01:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: VAAPI device "/dev/dri/renderD128" is AMD GPU
[2024-04-23 10:44:13.152 +01:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: VAAPI device "/dev/dri/renderD128" supports Vulkan DRM interop
[2024-04-23 10:44:13.152 +01:00] [INF] [1] MediaBrowser.MediaEncoding.Encoder.MediaEncoder: FFmpeg: "ffmpeg"
Is it possible to get this change merged into the binary that is distributed on the FreeBSD Ports or do you want testing from the other available VAAPI devices first? Looking at the logic of Jellyfin, they should work if the AMD GPU works, but I can understand if you'd prefer testing each device before adding it.
(I posted this by accident on my work account originally in case you see a duplicate comment @Thefrank )
@MACVTi
A couple of reason:
I want to make sure that I have correctly applied all of the patches before pushing out a new binary so it will remain a test until I get some feedback. QSV should work for Intel CPUs.
The test version is based off the upstream master branch which should be an actual release soon(tm).
The 10.8.x branch and tags throw NuGet security errors when building. These are easy to fix by bumping the versions of the depneds but I don't want to break something else while doing so.
That's understandable. Now that you say it, the version is 10.9.0, not 10.8.9 as I first read it. The release date on the Github page threw me off again! :)
If you want, I probably have a few Intel computers lying around so I should be able to try VA-API and QSV support for Intel in the next day or two if that's any help? I think that covers most of the configurations of HW Acceleration thats on FreeBSD anyway? (Maybe the raspberry pi but I'm not sure if drivers are available for FreeBSD). If you have a list of configurations that you'd like to get feedback on, I could see what I could do.
Also for my own curiosity, do you think there'd be much work in converting the port to be a true source port? I'm not too familiar with .NET myself to be honest. It would just be handy as we could submit pull requests with code we could test rather than having to hassle you!
If you want, I probably have a few Intel computers lying around so I should be able to try VA-API and QSV support for Intel in the next day or two if that's any help? I think that covers most of the configurations of HW Acceleration thats on FreeBSD anyway? (Maybe the raspberry pi but I'm not sure if drivers are available for FreeBSD). If you have a list of configurations that you'd like to get feedback on, I could see what I could do.
VAAPI and QSV are the ones mostly used by other mediaplayers on FreeBSD so those would be the best/first to try. If there is demand for it, I can look at CUDA and Vulkan.
Also for my own curiosity, do you think there'd be much work in converting the port to be a true source port?
It can be rather tedious to get setup initially. Maintaining is easier but requires manually updating all of the version numbers from the NuGet packages it uses. You can look at https://github.com/freebsd/freebsd-ports/tree/6dbb66a12e23526f7dc4f43f8c2cf7ae58f4be9f/devel/msbuild or https://github.com/Thefrank/freebsd-dotnet-sourcebuild/blob/main/PortWIP/dotNET8/Makefile if you want some examples. ASLR needs to be turned off and mlock
needs to be allowed in the build environment for dotNET builds. Jellyfin is further complicated by using SkiaSharp which requires Google's tooling to build.
This SOUNDS very complicated but it is mostly just a massive time sink.
I'm not too familiar with .NET myself to be honest. It would just be handy as we could submit pull requests with code we could test rather than having to hassle you!
I need to get something setup to make contributions outside of documentation updates easier.
Hello guys,
I would like to share my situation. I've been trying to enable hardware acceleration for my Jellyfin server using the instructions provided in this file Installation_TrueNAS_GUI.md. While I can see the
dri
anddrm
nodes inside my jails, videos requiring transcoding simply do not load. Below are the configurations of my system and the procedures I've followed:System Configuration
FreeBSD 13.2-RELEASE amd64
pciconf -vl
returns:Procedures Performed (Host)
Jail Creation and Jellyfin Installation
Created the Jail with
vnet=on
andallow_mlock=1
:Installed Jellyfin inside the Jail:
drm-kmod Installation and Module Loading
Installed the
drm-kmod
package:Added
i915kms
to thekld_list
in/etc/rc.conf
:Rebooted the system to load the new modules.
Verification of Loaded Modules and Device Nodes
Confirmed that the modules
i915kms
anddrm
were loaded usingkldstat
:Verified the creation of the nodes
/dev/drm
and/dev/dri
:Devfs Rules Configuration
Created the file
/etc/devfs.rules
with the following content:Restarted the
devfs
service:Applied the ruleset 10 to the Jellyfin Jail:
Inside the Jellyfin Jail
Properties of the Jellyfin jail:
Starting the Jellyfin jail:
Installing the packages:
Versions of the installed packages:
FFmpeg config:
Confirming that the jail can see the
drm
anddri
nodes:Result of the command
vainfo
:Added the user
jellyfin
to the groupvideo
:Created the file
/usr/local/bin/lffmpeg
with the following content:root@jellyfin:~ # cat /usr/local/bin/lffmpeg
Added execute permission to the file
/usr/local/bin/lffmpeg
:root@jellyfin:~ # ls -la /usr/local/bin/lffmpeg
:Playback settings on Jellyfin web:
When trying to load a movie, I notice that it never leaves the loading screen (it keeps spinning indefinitely with the loading circle):
The transcode log:
More logs:
I appreciate any tips you may have to offer. Thank you in advance.