Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hwdec=vaapi doesn't work with libmpv/render api #10424

Closed
g-fb opened this issue Jul 16, 2022 · 13 comments
Closed

hwdec=vaapi doesn't work with libmpv/render api #10424

g-fb opened this issue Jul 16, 2022 · 13 comments

Comments

@g-fb
Copy link

g-fb commented Jul 16, 2022

I have a player based on the qml render api example.
My problem is that hwdec=vaapi doesn't seem to work. I have tested hwdec=vaapi with different vo and added logs for each case. On my system with an nvidia card hwdec=nvdec it seems to work (no vo set) log

Same happens on an AMD system https://bugs.kde.org/show_bug.cgi?id=456482

Can someone clarify how hwdec is supposed to work with libmpv/render api? Is what the documentation says valid in this case too? Any ideas why vaapi doesn't work in my player?


CPU: Intel i5 2500K
GPU: Intel HD Graphics 3000


First case

hwdec=vaapi
vo=gpu

Video plays in separate window. Log: https://pastebin.com/p3eG1cPu

Second case

hwdec=vaapi
vo=vaapi

Doesn't play. Log: https://pastebin.com/jmWSUX2w

Third case

hwdec=vaapi
vo=libmpv

Plays in correct window. Log: https://pastebin.com/E3cvNHKv

Fourth case, not setting vo

hwdec=vaapi

Plays in correct window. Log: https://pastebin.com/7xRwWgba

@philipl
Copy link
Member

philipl commented Jul 16, 2022

What's the problem? Cases three and four are the only relevant ones and you say they are working correctly.

@g-fb
Copy link
Author

g-fb commented Jul 16, 2022

They work, but I don't think they use vaapi.

[   1.263][v][vd] Looking at hwdec h264-vaapi...
[   1.263][v][vd] Could not create device.
[   1.263][v][vd] No hardware decoding available for this codec.
[   1.263][v][vd] Using software decoding.

@philipl
Copy link
Member

philipl commented Jul 17, 2022

You need to provide the relevant native resource from your application that the vaapi hwdec will use to initialise itself - either the X11 display or the Wayland WL display, most likely.

See https://github.com/mpv-player/mpv/blob/master/video/out/gpu/libmpv_gpu.c#L26

@g-fb
Copy link
Author

g-fb commented Jul 17, 2022

I have added the needed info, at least I hope so (did the same as other players). But I still get the same

[vd] Looking at hwdec h264-vaapi...
[vd] Could not create device.
[vd] No hardware decoding available for this codec.
[vd] Using software decoding.

With mpv I get

[vd] Looking at hwdec h264-vaapi...
[vo/gpu] Loading hwdec driver 'vaapi-egl'
[vo/gpu/vaapi-egl] using VAAPI EGL interop
[vo/gpu/vaapi-egl] Trying to open a x11 VA display...
failed to open /usr/lib64/dri/hybrid_drv_video.so
Not using hybrid_drv_video.so
[vo/gpu/vaapi-egl/vaapi] Initialized VAAPI: version 1.14
[vo/gpu/vaapi-egl] Going to probe surface formats (may log bogus errors)...
[vo/gpu/vaapi-egl] Done probing surface formats.
[vo/gpu] Loading hwdec driver 'cuda-nvdec'
Cannot load libcuda.so.1
[vo/gpu/cuda-nvdec] Failed to load CUDA symbols
[vo/gpu] Loading failed.
[vo/gpu] Loading hwdec driver 'vdpau-gl'
[vo/gpu] Loading failed.
[vo/gpu] Loading hwdec driver 'drmprime-drm'
[vo/gpu/drmprime-drm] Failed to retrieve DRM fd from native display.
[vo/gpu] Loading failed.
[vd] Trying hardware decoding via h264-vaapi.
[vd] Selected codec: h264 (H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10)

@philipl
Copy link
Member

philipl commented Jul 18, 2022

I see now that you appear to be using the release 0.34.1. Please try again with mpv master. The logic for how hwdecs are loaded has changed significantly in master, and should help, or at least the expanded logging will help us understand what is going wrong.

@g-fb
Copy link
Author

g-fb commented Jul 18, 2022

mpv version: mpv 0.34.0-378-g8ef744d1b7

hwdec=vaapi log: https://pastebin.com/NLjTu5hL
hwdec=auto-safe log: https://pastebin.com/j33act7r

@philipl
Copy link
Member

philipl commented Jul 19, 2022

Ok. So based on your logs, you are not using EGL, and presumably using GLX in your application. hwdec=vaapi only works with OpenGL when you use EGL, as the interop mechanism is EGL specific.

@g-fb
Copy link
Author

g-fb commented Jul 21, 2022

Ok. So based on your logs, you are not using EGL, and presumably using GLX in your application.

So that means the context I give to mpv_render_context_create (through mpv_opengl_init_params) is an glx one and I need to give it an egl context?

@philipl
Copy link
Member

philipl commented Jul 21, 2022

I did a brief read of the Qt docs and it does not make clear what it's using underneath the OpenGL context. Some other discussions suggest it knows how to use GLX and EGL but I don't see an explanation of how it chooses. But to your question, there is an OpenGL context (and that's the one that Qt can give you) but underneath OpenGL you need to use a window system binding (WGL on windows, GLX on X11, EGL is crossplatform). When writing GL code directly, you will naturally pick one and know what you used. With Qt it's not clear. You'll need to dig and find out how to control this.

@g-fb
Copy link
Author

g-fb commented Jul 21, 2022

Ok, thank you for the help, really appreciate it.

@g-fb g-fb closed this as completed Jul 21, 2022
@g-fb
Copy link
Author

g-fb commented Jul 29, 2022

So it's possible to use egl with Qt, need to set the environment variable QT_XCB_GL_INTEGRATION="xcb_egl".

This doesn't work with mpv master (mpv 0.34.0-386-g284fecc0bd), but it does with mpv 0.34.1.

In the 0.34.1 log I have this:

[libmpv_render] Loading hwdec driver 'vaapi-egl'
[libmpv_render/vaapi-egl] using VAAPI EGL interop
[libmpv_render/vaapi-egl] Trying to open a x11 VA display...
[libmpv_render/vaapi-egl/vaapi] Initialized VAAPI: version 1.14
[libmpv_render/vaapi-egl] Going to probe surface formats (may log bogus errors)...
[libmpv_render/vaapi-egl] Done probing surface formats.

While in the master log I get:

[libmpv_render] Loading hwdec driver 'vaapi-egl'
[libmpv_render/vaapi-egl] using VAAPI EGL interop
[libmpv_render/vaapi-egl] Trying to open a wayland VA display...
[libmpv_render/vaapi-egl] Trying to open a drm VA display...
[libmpv_render/vaapi-egl] Could not create a VA display.
[libmpv_render] Loading failed.

@g-fb g-fb reopened this Jul 29, 2022
@philipl
Copy link
Member

philipl commented Jul 30, 2022

You need to have libxpresent-dev or equivalent for your distro installed. Master requires this X extension. If it's missing, X11 support is automatically disabled.

@g-fb
Copy link
Author

g-fb commented Jul 30, 2022

That was it, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants