jellyfin / jellyfin-media-player

Jellyfin Desktop Client
GNU General Public License v2.0
3.28k stars 324 forks source link

Choppy playback with vaapi hardware decoding #139

Open esmorun opened 3 years ago

esmorun commented 3 years ago

Hardware: Intel Pentium Silver J5005 / Intel® UHD Graphics 605 OS: Ubuntu 20.04

Steps to reproduce:

  1. Download and install the .deb package for version 1.6.1:
  2. Connect Jellyfin Media Player to a server and play a video with hardwareDecoding set to the default value of "decode.copy", or "decode.enabled".

Observed behavior: The video plays at about 1-10fps depending on resolution/quality. System monitor shows that one of the CPU cores is always maxed out at 100%. Sometimes the UI freezes completely. Jellyfinmediaplayer.log seem to indicate that vaapi is working: 2021-09-05 13:19:02 [ INFO ] PlayerComponent.cpp @ 587 - vd: Using hardware decoding (vaapi-copy).

Expected behavior: The video should play smoothly with low CPU usage like it does in the standalone version of MPV, even high quality ones such as h265 @4k resolution.

Notes: Wayland or X11 doesn't matter. Vaapi is working fine in MPV, Firefox and Kodi on the same system. I also have a more powerful system with a Ryzen processor and Nvidia GPU. Playback is smooth, but when looking at the system monitor I also see one cpu core spiking to 100%. Seems like a single thread is locking up the UI on lower end hardware?

barolo commented 3 years ago

can confirm, there's weird lag/choppiness with it enabled

iwalton3 commented 3 years ago

Maybe it has something to do with how it is rendered behind the web client. I'm unfortunately not really sure how to troubleshoot this. There's always using MPV Shim as a workaround but it's obviously less ideal than fixing the issue.

jluttine commented 2 years ago

Perhaps the issue is decode.copy and vaapi-copy. Copying might make decoding slow, as far as I understand. Setting decode.enable might help in principle, but probably it will still fall back to vaapi-copy and nothing changes in the performance. At least I haven't been able to use vaapi, just vaapi-copy. I don't know how to fix that.

jluttine commented 2 years ago

You could try running JMP as:

QT_XCB_GL_INTEGRATION="xcb_egl" jellyfinmediaplayer

and set hardware decoding to "enabled", not "copy".

Does that help? See: https://github.com/jellyfin/jellyfin-media-player/issues/231#issuecomment-1293408450

esmorun commented 2 years ago

You could try running JMP as:

QT_XCB_GL_INTEGRATION="xcb_egl" jellyfinmediaplayer

and set hardware decoding to "enabled", not "copy".

Does that help? See: #231 (comment)

Thank you for the suggestion, it doesn't seem to make a difference to me. I see this in the log:


2022-10-31 10:01:58 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Loading hwdec driver 'vaapi-egl' 
2022-10-31 10:01:58 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render/vaapi-egl: VAAPI hwdec only works with OpenGL or Vulkan backends. 
2022-10-31 10:01:58 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Loading failed. 

And later in the log it seems it falls back to vaapi-copy

2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Opening decoder h264 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Looking at hwdec h264-nvdec... 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Could not create device. 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Looking at hwdec h264-vaapi... 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Could not create device. 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Looking at hwdec h264-vdpau... 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Could not create device. 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Looking at hwdec h264-nvdec-copy... 
2022-10-31 10:03:22 [ ERROR ] PlayerComponent.cpp @ 594 - ffmpeg: AVHWDeviceContext: Cannot load libcuda.so.1 
2022-10-31 10:03:22 [ ERROR ] PlayerComponent.cpp @ 594 - ffmpeg: AVHWDeviceContext: Could not dynamically load CUDA 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Could not create device. 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Looking at hwdec h264-vaapi-copy... 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Window size: 2560x1440 (Borders: l=0 t=0 r=0 b=0) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Video source: 0x0 (0:0) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Video display: (0, 0) 1x1 -> (0, 0) 2560x1440 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Video scale: 2560.000000/1440.000000 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: OSD borders: l=-1073740544 t=0 r=-1073740544 b=0 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - libmpv_render: Video borders: l=0 t=0 r=0 b=0 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vaapi: Initialized VAAPI: version 1.14 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Trying hardware decoding via h264-vaapi-copy. 2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vd: Selected codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vf: User filter list: 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - vf:   (empty) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad: Codec list: 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad:     aac - AAC (Advanced Audio Coding) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad:     aac - AAC (Advanced Audio Coding) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad:     aac_fixed (aac) - AAC (Advanced Audio Coding) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad: Opening decoder aac 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad: Requesting 1 threads for decoding. 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - ad: Selected codec: aac (AAC (Advanced Audio Coding)) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - af: User filter list: 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - af:   (empty) 
2022-10-31 10:03:22 [ DEBUG ] PlayerComponent.cpp @ 588 - cplayer: Starting playback...
jluttine commented 2 years ago

Ok.. I had the same issue and that was fixed by launching JMP as I suggested. Could it be something similar but you need something else than Qt-related environment variable? I really don't know. But this discussion might be somewhat useful: https://github.com/mpv-player/mpv/issues/10424 Or maybe ask help from MPV team?