mpv icon indicating copy to clipboard operation
mpv copied to clipboard

hwdec=nvdec fails: invalid OpenGL context

Open SeongGino opened this issue 2 years ago • 3 comments

Important Information

  • mpv version: 0.34.0-578-g2e5d0d6e07 (current master) / mpv 0.34.1-5 Arch community release
  • Linux Distribution and Version: Arch Linux, updated as of 2022/11/07
  • Source of the mpv binary: AUR, built from master / Arch community release
  • If known which version of mpv introduced the problem: N/A
  • Window Manager and version: kwin_x11 5.26.2.1
  • GPU driver and version: NVIDIA RTX 3060 Ti LHR (desktop), running Proprietary 520.56.06 w/ CUDA 11.8.0 (if relevant)

Reproduction steps

Load any local/streamed video with --hwdec=nvdec or a config with hwdec=nvdec

Expected behavior

Video should render using hardware NVDEC.

Actual behavior

mpv falls back to software rendering entirely. hwdec=nvdec-copy works. Behavior is reproduced regardless of version used and --vo=gpu-next or not.

Log file

output.txt

Shouldn't need a sample file, it's reproduceable with any garden variety file (basic h.264 file used for ref).

FWIW, Haruna (a standalone video player using libmpv) does not have this issue and uses the GPU decoder just fine with the application set to use nvdec; it's only mpv itself that's affected.

SeongGino avatar Nov 08 '22 04:11 SeongGino

I've never seen this before. That call relies on implicit OpenGL and cuda state, and if it doesn't work, there's not much we can do. Your logs appear to show nvidia's OpenGL initialising correctly, but this kind of failure might indicate incorrectly installed GL or nvidia libraries.

You can also try with --gpu-api=vulkan

It's also worth rebooting.

philipl avatar Nov 08 '22 04:11 philipl

Your logs appear to show nvidia's OpenGL initialising correctly, but this kind of failure might indicate incorrectly installed GL or nvidia libraries.

Don't understand how that can be the case, because everything else GPU-related works perfectly fine; whether CUDA, OpenGL or otherwise.

You can also try with --gpu-api=vulkan

Using Vulkan seems to work, nvdec is loading now. output.txt But I'm not sure why it's failing on OGL.

SeongGino avatar Nov 08 '22 19:11 SeongGino

I don't have any more insights for you, except that this particular function call is doing something that is tied deeply into the CUDA OpenGL interop that nvidia has and it will require all the right library versions to be in use in various places. I can fully expect your regular OpenGL and regular CUDA use to be unaffected because nothing else is trying to exercise the interop.

philipl avatar Nov 08 '22 20:11 philipl

I'm facing the exact same issue. Is there any specific flag that I should look for when compiling mpv or ffmpeg?

fulalas avatar Dec 13 '22 05:12 fulalas

@fulalas no build flags to fix afaik; you'll have to use the aforementioned Vulkan api output to workaround the problem for now (still the same issue up to 525.60.11 w/ CUDA 12).

SeongGino avatar Dec 13 '22 06:12 SeongGino

I found a workaround! I noticed that by using mpv build script (the one that creates a static version of mpv) nvdec works intead of falling back to nvdec-copy -- I just had to edit ffmpeg-config script and at line 16 (the one that starts with OPTIONS=) add --enable-nvenc.

Then I tried to manually compile libplacebo hoping that mpv could find it and enable some features, and after building mpv: voila, nvdec is working. So I guess mpv doesn't like to not have libplacebo.

BTW, vulkan api doesn't work for me in mpv -- although vulkan itself runs just fine (e.g. vl quake, demos, etc).

fulalas avatar Dec 13 '22 06:12 fulalas

Sorry, guys, I was wrong. What actually fixed this issue was not libplacebo, but having ffnvcodec-headers package installed when building mpv.

I'm gonna check in another topic if mpv should complain about the missing headers if it detects ffmpeg was builti with --enable-nvenc.

Thank you all :)

fulalas avatar Dec 14 '22 07:12 fulalas

Seems to be just missing ffnvcodec-headers (there's another issue about that) so closing.

Dudemanguy avatar Aug 09 '23 04:08 Dudemanguy

Sorry to necro, but it would be prudent for me to add that I've noticed using mpv's nvdec w/ vulkan api (still the only way I can get nvdec to work with mpv on its own) causes extra hitching with, exclusively, GTK4 apps. Though I can't reproduce this on other apps using libmpv and the same backend, e.g. Haruna Player, so it's extra confusing why this is happening with the main mpv player.

Using normal repository packages from Arch, everything's up-to-date, so...

SeongGino avatar Oct 09 '23 18:10 SeongGino