Server version: 1.30.0.6486 (Docker/linuxserver.io)
Player version: 1.32.2.3478-f6005c91 (plex-htpc Flatpak)
I’ve been unable to get hardware acceleration working properly for video playback for the Plex HTPC linux app on my system - it stutters unless I disable Hardware Acceleration in the settings. There are some things I’ve tried that have improved things somewhat, and I go into detail with those a little later in this post.
My system is a NUC w/ Intel Celeron J3455 (Intel Broxton), OS is Elementary OS 5.
Speculation
I think it’s a driver issue related to the integrated graphics - although it from what I’ve seen it looks like hardware acceleration is a common issue with the J3455 in general. Chucking the phrase “J3455” into a search engine brings up a few posts with other people having similar issues with other software.
Trying to narrow things down
Since Plex appears to be using MPV for playback, I thought it’d be a good idea to start there. 4K media used for testing is in HEVC format, and 1080p media used for testing in h.264 format. All media (except Live TV) is played with Direct Play.
I’m just a tinkerer and not an expert on any of this stuff, so it’s likely some things have been overlooked while trying to figure out why this isn’t working.
MPV - 4K playback capability
Installed from native package manager
I’ve confirmed smooth 4K 60FPS playback on my system using a native installation of MPV, and intel_gpu_top.
Installed with Flatpak
Using the Flatpak version of MPV results in horrible stuttering, almost identical to the stuttering behavior in Plex HTPC. The video is unwatchable, barely chugging by at 1-2FPS, and the audio is desynchronised.
This is seemingly fixed by manually passing --hwdec=auto
on the command line, enabling smooth 4K 60FPS playback in Flatpak MPV
flatpak run io.mpv.Mpv -v --hwdec=auto "/home/htpc/Downloads/BigBuckBunny4k60fps.mp4"
Plex HTPC (Flatpak) - 4K playback
Hardware acceleration ON
Switching gears and heading into Plex HTPC, the default 4K playback behavior is same as described earlier - chugging at 1-2FPS with desynchronised audio. 1080p playback is the same, although chugging at a slightly faster framerate but still with desynchronised audio.
Pressing CTRL+SHIFT+D, the debug overlay indicates vaapi-copy
being used for hardware acceleration.
Diving into the logs, a few things seem to be happening?
-
vaapi-egl
fails to load (passing--env=QT_XCB_GL_INTEGRATION=xcb_egl
to the flatpak sadly makes no difference) - MPV is failing to ‘create a device’ for
hevc-vaapi
, falling back tohevc-vaapi-copy
...
Feb 05, 2023 22:57:05.462 [0x7f1771cf4640] DEBUG - GL_VENDOR: Intel
Feb 05, 2023 22:57:05.462 [0x7f1771cf4640] DEBUG - GL_RENDERER: Mesa Intel(R) HD Graphics 500 (APL 2)
Feb 05, 2023 22:57:05.462 [0x7f1771cf4640] DEBUG - GL_VERSION: 4.6 (Compatibility Profile) Mesa 21.3.9 (git-78c96ae5b6)
...
Feb 05, 2023 22:57:05.465 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: GL_VERSION='4.6 (Compatibility Profile) Mesa 21.3.9 (git-78c96ae5b6)'
Feb 05, 2023 22:57:05.465 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: Detected desktop OpenGL 4.6.
Feb 05, 2023 22:57:05.465 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: GL_VENDOR='Intel'
Feb 05, 2023 22:57:05.465 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: GL_RENDERER='Mesa Intel(R) HD Graphics 500 (APL 2)'
Feb 05, 2023 22:57:05.465 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: GL_SHADING_LANGUAGE_VERSION='4.60'
Feb 05, 2023 22:57:05.466 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: Loaded extension GL_KHR_debug.
Feb 05, 2023 22:57:05.466 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: GL_*_swap_control extension missing.
Feb 05, 2023 22:57:05.478 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: Testing FBO format rgba16f
Feb 05, 2023 22:57:05.478 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: Using FBO format rgba16f.
Feb 05, 2023 22:57:05.478 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: No advanced processing required. Enabling dumb mode.
Feb 05, 2023 22:57:05.478 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render: Loading hwdec driver 'vaapi-egl'
Feb 05, 2023 22:57:05.478 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] libmpv_render/vaapi-egl: VAAPI hwdec only works with OpenGL or Vulkan backends.
...
Feb 05, 2023 22:57:54.378 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Codec list:
Feb 05, 2023 22:57:54.378 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: hevc - HEVC (High Efficiency Video Coding)
Feb 05, 2023 22:57:54.378 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Opening decoder hevc
Feb 05, 2023 22:57:54.378 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Looking at hwdec hevc-vaapi...
Feb 05, 2023 22:57:54.378 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Could not create device.
Feb 05, 2023 22:57:54.378 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Looking at hwdec hevc-vaapi-copy...
Feb 05, 2023 22:57:54.380 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vaapi: Initialized VAAPI: version 1.15
Feb 05, 2023 22:57:54.380 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Trying hardware decoding via hevc-vaapi-copy.
Feb 05, 2023 22:57:54.381 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vd: Selected codec: hevc (HEVC (High Efficiency Video Coding))
...
Feb 05, 2023 22:58:16.488 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: starting AO
Feb 05, 2023 22:58:16.670 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] vo/libmpv: mpv_render_context_render() not being called or stuck.
Feb 05, 2023 22:58:16.844 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: audio end or underrun
Feb 05, 2023 22:58:17.061 [0x7f1819ffa900] DEBUG - [InputManager] Input received: source: Keyboard keycode: Alt+0xffe9V:3
Feb 05, 2023 22:58:17.061 [0x7f1819ffa900] DEBUG - [InputManager] No match for: Alt+0xffe9V
Feb 05, 2023 22:58:17.295 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio device underrun detected.
Feb 05, 2023 22:58:17.295 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] cplayer: restarting audio after underrun
Feb 05, 2023 22:58:17.295 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: starting AO
Feb 05, 2023 22:58:17.627 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: audio end or underrun
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio device underrun detected.
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] cplayer: restarting audio after underrun
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer:
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio/Video desynchronisation detected! Possible reasons include too slow
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: hardware, temporary CPU spikes, broken drivers, and broken files. Audio
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: position will not match to the video (see A-V status field).
Feb 05, 2023 22:58:18.033 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer:
Feb 05, 2023 22:58:18.035 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: starting AO
Feb 05, 2023 22:58:18.243 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: audio end or underrun
Feb 05, 2023 22:58:18.772 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio device underrun detected.
Feb 05, 2023 22:58:18.772 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] cplayer: restarting audio after underrun
Feb 05, 2023 22:58:18.777 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: starting AO
Feb 05, 2023 22:58:18.987 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: audio end or underrun
Feb 05, 2023 22:58:19.511 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio device underrun detected.
Feb 05, 2023 22:58:19.511 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] cplayer: restarting audio after underrun
Feb 05, 2023 22:58:19.511 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: starting AO
Feb 05, 2023 22:58:19.845 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: audio end or underrun
Feb 05, 2023 22:58:20.251 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio device underrun detected.
Feb 05, 2023 22:58:20.251 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] cplayer: restarting audio after underrun
Feb 05, 2023 22:58:20.252 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: starting AO
Feb 05, 2023 22:58:20.461 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] ao/pulse: audio end or underrun
Feb 05, 2023 22:58:20.989 [0x7f17f0ff9640] WARN - [MPVEngine/mpv] cplayer: Audio device underrun detected.
Feb 05, 2023 22:58:20.989 [0x7f17f0ff9640] DEBUG - [MPVEngine/mpv] cplayer: restarting audio after underrun
MPV’s logs appear to show the ‘wrong’ driver being loaded for VAAPI (iHD drivers apparently do not have proper support for Broxton, whereas i965 drivers do?). We’ll revisit this shortly…
[ 49.584][v][vd] Codec list:
[ 49.584][v][vd] hevc - HEVC (High Efficiency Video Coding)
[ 49.584][v][vd] Opening decoder hevc
[ 49.584][v][vd] Looking at hwdec hevc-vaapi...
[ 49.584][v][vd] Could not create device.
[ 49.584][v][vd] Looking at hwdec hevc-vaapi-copy...
[ 49.584][d][vaapi] libva: VA-API version 1.15.0
[ 49.584][d][vaapi] libva: Trying to open /app/bin/../lib/dri/iHD_drv_video.so
[ 49.584][d][vaapi] libva: Found init function __vaDriverInit_1_15
[ 49.585][d][vaapi] libva: va_openDriver() returns 0
[ 49.585][v][vaapi] Initialized VAAPI: version 1.15
[ 49.585][d][ffmpeg] AVHWDeviceContext: VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 22.4.4 (2bbbd9bc).
[ 49.585][d][ffmpeg] AVHWDeviceContext: Driver not found in known nonstandard list, using standard behaviour.
[ 49.585][v][vd] Trying hardware decoding via hevc-vaapi-copy.
[ 49.586][v][vd] Selected codec: hevc (HEVC (High Efficiency Video Coding))
Hardware acceleration OFF
Disabling hardware acceleration allows 1080p playback at a smooth framerate. 4K is still unwatchable, stuttering as expected (the J3455 isn’t exactly a beast of a CPU) but it’s actually playing back faster than using the hardware acceleration.
I would be OK with this if the Live TV worked - but it sadly doesn’t with hardware acceleration off (playback video is desynchronised with audio), so I’m looking for a solution again.
Hardware acceleration ON (with LIBVA_DRIVER_NAME=i965
)
Arch AUR forums to the rescue! A user suggested passing an additional LIBVA_DRIVER_NAME
environment variable to the application.
I still passed QT_XCB_GL_INTEGRATION=xcb_egl
, although as noted earlier this variable seemingly has no effect.
flatpak run --env=QT_XCB_GL_INTEGRATION=xcb_egl --env=LIBVA_DRIVER_NAME=i965 tv.plex.PlexHTPC
4K now plays back at around roughly 15-20fps (still unwatchable sadly) and slows down the interface’s responsiveness during playback, and Live TV audio is desynchronised. vaapi-copy
is still being used when checking the debug menu.
1080p h.264 content now plays back smoothly though, which means we’re getting somewhere!
Diving into the logs, everything looks practically identical, with a few exceptions
- Errors referencing desynchronisation have disappeared
- in MPV’s logfile, the i965 driver (referencing Broxton in the driver name) is loaded for VAAPI, instead of the iHD one. See below
[ 18.095][v][vd] Codec list:
[ 18.095][v][vd] hevc - HEVC (High Efficiency Video Coding)
[ 18.095][v][vd] Opening decoder hevc
[ 18.095][v][vd] Looking at hwdec hevc-vaapi...
[ 18.095][v][vd] Could not create device.
[ 18.095][v][vd] Looking at hwdec hevc-vaapi-copy...
[ 18.095][d][vaapi] libva: VA-API version 1.15.0
[ 18.095][d][vaapi] libva: User environment variable requested driver 'i965'
[ 18.095][d][vaapi] libva: Trying to open /app/bin/../lib/dri/i965_drv_video.so
[ 18.095][d][vaapi] libva: Found init function __vaDriverInit_1_15
[ 18.095][d][vaapi] libva: va_openDriver() returns 0
[ 18.095][v][vaapi] Initialized VAAPI: version 1.15
[ 18.095][d][ffmpeg] AVHWDeviceContext: VAAPI driver: Intel i965 driver for Intel(R) Broxton - 2.4.1.
[ 18.095][d][ffmpeg] AVHWDeviceContext: Driver not found in known nonstandard list, using standard behaviour.
[ 18.095][v][vd] Trying hardware decoding via hevc-vaapi-copy.
[ 18.096][v][vd] Selected codec: hevc (HEVC (High Efficiency Video Coding))
No resolution, yet…
and TL;DR
TL;DR: QT_XCB_GL_INTEGRATION=xcb_egl
has no effect. Using flatpak run --env=QT_XCB_GL_INTEGRATION=xcb_egl --env=LIBVA_DRIVER_NAME=i965 tv.plex.PlexHTPC
improves things noticeably, but stuttering still exists in some situations.
This is sadly where my efforts have come to a close as of now. Can provide more details or logs if needed.