mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
26.93k stars 2.84k forks source link

Vulkan Video Decoding: Usage Guide and FAQ #11739

Closed philipl closed 3 months ago

philipl commented 1 year ago

Vulkan Video Decoding: Usage Guide and FAQ

On the 28th of May, we reached the significant milestone of finally merging all the required functionality into ffmpeg, libplacebo, and mpv to do end-to-end Vulkan video decoding and presentation. Although the functionality is now all there, we still have a complex landscape in terms of what is supported on what hardware and with what drivers. This document attempts to lay out all the requirements and limitations, so you have a chance of successfully using the feature.

Why should I even care about Vulkan video decoding?

It's a fair question. Right now, the actual functionality you gain access to is not terribly different from what you would get with existing video decoding APIs that ffmpeg and mpv already support. However, Vulkan video decoding has the potential to be a credible cross-vendor, cross-platform API that is well supported, and can work efficiently with Vulkan based filtering and post-processing. In the short term, there will be rough edges, and only a narrow set of supported codecs (only H.264 and H.265 are standardised today, with AV1 still a work in progress), but in the future, it will hopefully be the most performant and capable way to do hardware decoding and processing.

Software Requirements

We have finally reached the point where all the required components have made official releases. Ensure you are running with the following releases or newer:

These requirements mean you will likely have to compile everything for yourself (especially on Linux), but Shinchiro's windows builds appear to be functional.

Hardware and Driver Requirements

Usage

The basic command line arguments:

mpv --vo=gpu-next --gpu-api=vulkan --hwdec=vulkan

Depending on your system configuration, you may additionally need to force the right gpu-context:

Capabilities

Jules-A commented 1 year ago

AMD on Windows appears to be 5000/6000 series according to https://www.amd.com/en/support/kb/release-notes/rn-rad-win-22-11-2-vlk-video-code-decode (possibly 7000 works?). It doesn't work on Polaris: 0.339][e][ffmpeg/video] h264: Device does not support the VK_KHR_video_decode_queue extension!

llyyr commented 1 year ago

After bc28dce303a4abcc8ec2f1fd941bc1bfd02e6f79, you need to patch your Mesa with this PR to get AV1 decoding on radv.

aufkrawall commented 1 year ago

Reliably crashes driver for me with this sample: https://0x0.st/HbHJ.mkv Other files seem to work for whatever reason (hwdec beeing used confirmed). Latest git-master of mpv, libplacebo, ffmpeg and radv on 6700 xt.

philipl commented 1 year ago

Sounds like you probably need to file a mesa issue for that - and even if it was an mpv issue, please open a separate one. This FAQ isn't the place to report it.

cyanreg commented 1 year ago

@aufkrawall AMD currently needs https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23227 to avoid crashes, which also fixes quite a lot of bugs

alakittty commented 1 year ago
 (+) Video --vid=1 (*) (hevc 3828x1592 23.976fps)
 (+) Audio --aid=1 --alang=eng (*) (eac3 6ch 48000Hz)
     Subs  --sid=1 --slang=eng (subrip)
     Subs  --sid=2 --slang=eng 'SDH' (subrip)
     Subs  --sid=3 --slang=fre (subrip)
[vo/gpu-next/libplacebo] vk->CreateDevice(vk->physd, &dinfo, PL_VK_ALLOC, &vk->dev): VK_ERROR_OUT_OF_HOST_MEMORY (../../../../../src_packages/libplacebo/src/vulkan/context.c:1308)
[vo/gpu-next/libplacebo] Failed creating logical device!
[vo/gpu-next/libplacebo] Failed initializing vulkan device
[vo/gpu-next] Failed initializing any suitable GPU context!
Error opening/initializing the selected video_out (--vo) device.
Video: no video

what does this error mean, my device has amd and i used the following config mpv --vo=gpu-next --gpu-api=vulkan --hwdec=vulkan --gpu-context=winvk mpv was working fine with gpu-next and gpu-api=vulkan till yesterdays' shinchiro release. todays release gave me this error maybe @shinchiro needs to bump libplacebo and ffmpeg version as per required?

Jules-A commented 1 year ago

AMD on Windows Special 22.11.2 drivers with video decoding support Hardware supported by those drivers (documented as 5000/6000 series. Apparently not newer 7000 series)

I don't know if that specific driver is required, they may have been included in 23.2.1 where they added other extensions, the driver notes aren't clear. 7000 series wasn't launched when the 22-11-2 Vulkan video drivers were released so that driver doesn't officially support them. If they did include the video extensions in newer drivers then they may support 7000 series but someone with those GPUs will need to test.

cyanreg commented 1 year ago

Yeah, I've reported to nvidia months ago that their descriptor buffer implementation is broken, but they haven't fixed it yet. If you want filters working, ask nvidia to fix it.

philipl commented 1 year ago

I found this video will white screen when using ffmpeg vulkan decoding, SW decoding or nvpro vk_video_decoder have no problem, I don't know if this is also NVIDIA's problem (also already reported to NVIDIA) test.mp4

Github claims you attached an audio-only file...

llyyr commented 1 year ago

That file is also broken on anv, it's glitchy and the decode is very slow while utilizing 100% of Render/3D engine.

philipl commented 1 year ago

That file is also broken on anv, it's glitchy and the decode is very slow while utilizing 100% of Render/3D engine.

It's an HEVC file. My experience on ANV is that any HEVC playback pegs the GPU at 100%

philipl commented 1 year ago

Also:

[ffmpeg/video] hevc: First slice in a frame missing.

This is a highly questionable sample.

lavilao commented 1 year ago

Will this work with hasvk in the future? I tried using it through wine (I dont want to have to compile everything) and got this error [ffmpeg/video] h264: Device does not support the VK_KHR_video_decode_queue extension! even though the output of vulkaninfo is:

vulkaninfo | grep video                                                                     ✔  10s  
    VK_KHR_video_decode_h264                    : extension revision 8
    VK_KHR_video_decode_queue                   : extension revision 7
    VK_KHR_video_queue                          : extension revision 8
            videoCodecOperations:
            videoCodecOperations: count = 1
CharlesMengCA commented 1 year ago

NVIDIA 1650 Super, Tested on windows with: mpv --vo=gpu-next --gpu-api=vulkan --hwdec=vulkan --gpu-context=winvk 5 videos played OK.

This video has problem: https://4kmedia.org/sony-whale-in-tonga-hdr-uhd-4k-demo/ Switched back to hwdec=nvdec, the problem is gone.

image

24fpsDaVinci commented 1 year ago

for fedora, you need to edit mesa.spec and rebuild with codecs enabled -D video-codecs=h264dec,h264enc,h265dec,h265enc,vc1dec, codecs is disabled by default.

https://github.com/rpmfusion-infra/fedy/issues/110

https://themaister.net/blog/2023/01/05/vulkan-video-shenanigans-ffmpeg-radv-integration-experiments/

https://forum.endeavouros.com/t/compiling-mesa-22-2-with-codec-support-the-easy-way/30390

lavilao commented 1 year ago

works well with intel 11th gen igpu

for those @lavilao with [ffmpeg/video] h264: Device does not support the VK_KHR_video_decode_queue extension! make sure to enable mesa video codecs as stated here: https://themaister.net/blog/2023/01/05/vulkan-video-shenanigans-ffmpeg-radv-integration-experiments/ https://forum.endeavouros.com/t/compiling-mesa-22-2-with-codec-support-the-easy-way/30390

Screenshot from 2023-06-01 11-03-44

(small bug: pressing Ctrl+H will toggle vaapi instead of vulkan)

I enabled them. Check the vulkaninfo log, it shows the extension but mpv does not recognizes it. This is what I used to compile it

meson .. --reconfigure -D b_lto=true -D b_pgo=off -D platforms=x11,wayland -D buildtype=release -D prefix="$HOME/anv-master-video" --libdir="$HOME/anv-master-video/lib" -D b_ndebug=true -D gallium-drivers= -D vulkan-drivers=intel_hasvk -D gles1=disabled -D gles2=disabled -D opengl=false -D video-codecs=h264dec,h264enc,h265dec -D vulkan-beta=true
24fpsDaVinci commented 1 year ago

@lavilao i assume you're using Shinchiro's windows build? I haven't tried using mpv through wine, you may need to recompile.

zhengqwe commented 1 year ago
(+) Video --vid=1 (*) (hevc 3840x1608 24.000fps)
(+) Audio --aid=1 --alang=chi (*) (eac3 6ch 48000Hz)
    Audio --aid=2 --alang=chi (*) (aac 2ch 44100Hz)
[vo/gpu-next/libplacebo] Missing device feature: dynamicRendering
[vo/gpu-next/libplacebo] Vulkan device does not support all required features!
[vo/gpu-next/libplacebo] Failed creating logical device!
[vo/gpu-next/libplacebo] Failed initializing vulkan device
[vo/gpu-next] Failed initializing any suitable GPU context!
Error opening/initializing the selected video_out (--vo) device.
Video: no video

what does this error mean, my device has intel gpu, and i used the following config mpv --vo=gpu-next --gpu-api=vulkan --hwdec=vulkan --gpu-context=winvk using the latest shinchiro release.

llyyr commented 1 year ago

Intel on Windows does not support Vulkan hwdec, read the OP

Quackdoc commented 1 year ago

Might be mistaken, but this appears to have allowed zero copy hwacceleration on my polaris on radv. seems like preformance is a bit better too

lavilao commented 1 year ago

@lavilao i assume you're using Shinchiro's windows build? I haven't tried using mpv through wine, you may need to recompile.

I recompiled on a arch distrobox and the good news is it detects it. The bad news are that the logs show a driver bug:

 (+) Video --vid=1 (*) (h264 1278x720 30.000fps)
 (+) Audio --aid=1 --alang=eng (*) (opus 2ch 48000Hz)
[vo/gpu-next/wayland] GNOME's wayland compositor lacks support for the idle inhibit protocol. This means the screen can blank during playback.
MESA-INTEL: warning: ../src/intel/vulkan_hasvk/anv_formats.c:784: FINISHME: support more multi-planar formats with DRM modifiers
Using hardware decoding (vulkan).
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu-next] 1278x720 vulkan[nv12]
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next] Failed presenting frame!
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] Retrieving query pool results: VK_ERROR_DEVICE_LOST (../src/vulkan/gpu.c:103)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] Retrieving query pool results: VK_ERROR_DEVICE_LOST (../src/vulkan/gpu.c:103)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] Failed holding swapchain image for presentation
[vo/gpu-next] Failed presenting frame!
AV: 00:00:00 / 00:08:13 (0%) A-V:  0.000
[ffmpeg] av_log callback called with bad parameters (NULL AVClass).
[ffmpeg] This is a bug in one of Libav/FFmpeg libraries used.
[ffmpeg] Unable to submit command buffer: VK_ERROR_DEVICE_LOST
[ffmpeg/video] h264: get_buffer() failed
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
Error while decoding frame (hardware decoding)!
[ffmpeg] av_log callback called with bad parameters (NULL AVClass).
[ffmpeg] This is a bug in one of Libav/FFmpeg libraries used.
[ffmpeg] Unable to submit command buffer: VK_ERROR_DEVICE_LOST
[ffmpeg/video] h264: get_buffer() failed
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
Error while decoding frame (hardware decoding)!
[ffmpeg] av_log callback called with bad parameters (NULL AVClass).
[ffmpeg] This is a bug in one of Libav/FFmpeg libraries used.
[ffmpeg] Unable to submit command buffer: VK_ERROR_DEVICE_LOST
[ffmpeg/video] h264: get_buffer() failed
[ffmpeg/video] h264: decode_slice_header error
[ffmpeg/video] h264: no frame!
Error while decoding frame (hardware decoding)!
[ffmpeg] av_log callback called with bad parameters (NULL AVClass).
[ffmpeg] This is a bug in one of Libav/FFmpeg libraries used.
[ffmpeg] Unable to submit command buffer: VK_ERROR_DEVICE_LOST
Falling back to software decoding.
[ffmpeg/video] h264: co located POCs unavailable
[ffmpeg/video] h264: co located POCs unavailable
AV: 00:00:00 / 00:08:13 (0%) A-V:  0.000
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] Retrieving query pool results: VK_ERROR_DEVICE_LOST (../src/vulkan/gpu.c:103)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] vkQueueSubmit2: VK_ERROR_DEVICE_LOST (../src/vulkan/command.c:358)
[vo/gpu-next/libplacebo] Failed holding swapchain image for presentation
[vo/gpu-next] Failed presenting frame!
AV: 00:00:00 / 00:08:13 (0%) A-V:  0.000

Exiting... (Quit)
cyanreg commented 1 year ago

Ah, hasvk (old Intel GPUs) has a PR to implement video decoding that hasn't been merged yet: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21183

lavilao commented 1 year ago

@cyanreg thats the version I am using

zhengqwe commented 1 year ago
(+) Video --vid=1 (*) (hevc 3840x1608 24.000fps)
(+) Audio --aid=1 --alang=chi (*) (eac3 6ch 48000Hz)
    Audio --aid=2 --alang=chi (*) (aac 2ch 44100Hz)
[vo/gpu-next/libplacebo] Missing device feature: dynamicRendering
[vo/gpu-next/libplacebo] Vulkan device does not support all required features!
[vo/gpu-next/libplacebo] Failed creating logical device!
[vo/gpu-next/libplacebo] Failed initializing vulkan device
[vo/gpu-next] Failed initializing any suitable GPU context!
Error opening/initializing the selected video_out (--vo) device.
Video: no video

what does this error mean, my device has intel gpu, and i used the following config mpv --vo=gpu-next --gpu-api=vulkan --hwdec=vulkan --gpu-context=winvk using the latest shinchiro release.

Make sure your GPU is Gen12 or higher (TigerLake+), and update the driver to 4311 or higher

i use i3-10110u's gpu. so I still use d3d11va now. it works well.

kkost commented 1 year ago

I usually use vo=dmabuf-wayland but noticed that it's causing a segfault when vulkan interop is compiled in (even when it's not being used). Seems like when using dmabuf-wayland it attempts to run through loading every hwdec option even if one is explicitly specified.

Happy to use gpu-next but thought I should note this bug. But also curious if this will work with dmabuf-wayland in the future?

garoto commented 1 year ago

Someone make this into a Wiki entry so I can stop get notifications. Clearly not shithub issue material.

philipl commented 1 year ago

Someone make this into a Wiki entry so I can stop get notifications. Clearly not shithub issue material.

Believe me, I've thought about it. If it was a wiki page, it would still need an issue to be able to pin to the issues page. If locked, it would lead to people filing new issues. You can unsubscribe from this one more easily than unsubscribing from newly filed ones.

garoto commented 1 year ago

Believe me, I've thought about it. If it was a wiki page, it would still need an issue to be able to pin to the issues page. If locked, it would lead to people filing new issues. You can unsubscribe from this one more easily than unsubscribing from newly filed ones.

I believe you, which is really sad. These web-based git front-ends have nothing new to offer nowadays in terms of usability, every shithub new "feature" for the past 4yrs or so is nothing more than a detriment for browser performance and with questionable interface changes... but I digress. Will unsubscribe from this issue and everyone can carry on.

philipl commented 1 year ago

I usually use vo=dmabuf-wayland but noticed that it's causing a segfault when vulkan interop is compiled in (even when it's not being used). Seems like when using dmabuf-wayland it attempts to run through loading every hwdec option even if one is explicitly specified.

Happy to use gpu-next but thought I should note this bug. But also curious if this will work with dmabuf-wayland in the future?

It's a bug, and I've pushed a fix. Thanks for reporting.

cyanreg commented 1 year ago

The Sony swordsmith sample got fixed on radv with the following mesa PR: https://gitlab.freedesktop.org/airlied/mesa/-/commits/radv-video-fix-hevc-wip There was also a bug in ffmpeg, fixed with https://github.com/FFmpeg/FFmpeg/commit/65a1e8ee2c4a9c2f325e1921daab915689d9c9fd. Could anyone check if that fixed it on nvidia?

Akczht commented 1 year ago

macOS Sonoma, is introducing a translation layer, and that requires dxvk, will macOS Sonoma be bringing vulkan support ? as I've seen it's basically wine/crossover and brings support for dx11 and dx12, and only dxvk supports that in foss.

Akczht commented 1 year ago

macOS Sonoma, is introducing a translation layer, and that requires dxvk, will macOS Sonoma be bringing vulkan support ? as I've seen it's basically wine/crossover and brings support for dx11 and dx12, and only dxvk supports that in foss.

This is unlikely, but we can expect MoltenVK Vulkan 1.3

Actually, I heard it's not dxvk, it's some apple's own dx-to-metal translation.

cyanreg commented 1 year ago

With the latest ffmpeg and mesa, all issues have been solved, and decoding on AMD works perfectly. If there are any bugs left, they're very likely in the driver. So start reporting issues to them as well, if you can.

TheGentleChainsaw commented 1 year ago

I'm looking to set up my mpv so it can auto-switch between VVD and NVDec depending on the video codec. How exactly do I write a conditional auto-profile that only enables VVD on videos with H.264 or H.265? I know I'd probably have to match h264/hevc at the start of the video-codec property, but I'm not familiar enough with Lua scripting to write the condition myself.

Riteo commented 1 year ago

@arm64-v9a I wanted to do something similar but setting hwdec at that stage proved to be unreliable and segfaults the whole thing. I had to make a script that waited for a video-reconfig event and then tried fallbacking if there was some failure with Vulkan, kinda like #11808.

I can share the script if you (or somebody else) wants.

Akczht commented 1 year ago

@Riteo video decoding on an intel cpu is the best thing you can do, if you have an intel cpu 10th gen or higher, using nvdec is not needed as cpu hwdec will handle the codecs such as h264, h265, vp9 maybe av1 too.

Riteo commented 1 year ago

@arm64-v9a

This profile works fine with winvk+nvdec on NVIDIA, segment errors may be a problem with your driver

Might be, mainline head of ffmpeg segfaults too. Kinda weird that it works when changed after video-reconfig. I could file a ticket at mesa's repo, I'd have to ask them for more info I think.

@Akczht I don't have an intel CPU, I have an AMD Ryzen 5 3500U, a mobile processor with IGP. I'd like to start using Vulkan Video to find more problems and help polish the standard's implementations by reporting bugs like the aforementioned segfault.

cyanreg commented 1 year ago

Post sample?

Akczht commented 1 year ago

What is cpu hwdec? If you mean qsv-copy, this hwdec does work well, but DV metadata will be lost

hwdec=d3d11va

Akczht commented 1 year ago

@Akczht I don't have an intel CPU, I have an AMD Ryzen 5 3500U, a mobile processor with IGP. I'd like to start using Vulkan Video to find more problems and help polish the standard's implementations by reporting bugs like the aforementioned segfault.

Now that I think about it, I should also use vulkan, to test the stuff.

Riteo commented 1 year ago

@Akczht

hwdec=d3d11va

I'm pretty sure that it's not done on the CPU; the man page says:

requires --vo=gpu with --gpu-context=d3d11 --gpu-context=angle (Windows 8+ only)

Riteo commented 1 year ago

@cyanreg

Post sample?

If you mean video samples for testing, the Kodi wiki has lots: https://kodi.wiki/view/Samples

Akczht commented 1 year ago

@Akczht

hwdec=d3d11va

I'm pretty sure that it's not done on the CPU; the man page says:

requires --vo=gpu with --gpu-context=d3d11 --gpu-context=angle (Windows 8+ only)

I don't know exactly, but it's not software i.e. sometimes buggy and power efficient and built into the hardware.

cyanreg commented 1 year ago

@Riteo I meant one that causes a segfault

Riteo commented 1 year ago

@cyanreg here's what I know:

I run mpv on sway (Wayland compositor) on a weird musl-based "meta-distro" (KISS Linux) so mine is definitely not a common setup. I don't think that this should matter in this case but it never hurts to say.

mpv.conf:

vo=gpu-next
gpu-context=waylandvk
gpu-api=vulkan
hwdec=vaapi

[vulkan]
profile-cond= p["video-format"] == "h264" or  p["video-format"] == "hevc"
profile-restore=copy
hwdec=vulkan

With the configuration above, playing the file over at https://dl.ganjanetwork.ru/Files/Video%20Test%20Files/Bitrate/Birds/bird20.mkv returns:

~/test $ mpv ./bird20.mkv
 (+) Video --vid=1 (*) (h264 1920x1072 23.976fps)
Using hardware decoding (vaapi).
[auto_profiles] Applying auto profile: vulkan 
Segmentation fault

I also built mesa, ffmpeg, libplacebo and mpv with debug symbols (but still with optimizations), disabled the stripping pass of my package manager (kiss, source based) and ran the same command above through GDB. Here's what came from it:

Stack trace ``` #0 0x00007ffff7fc396a in memset () from /lib/ld-musl-x86_64.so.1 #1 0x00007ffff717badb in set_sps (vksps=0x7ffff34d3590, vksps_vui=0x7ffff34d3090, vksps_vui_header=0x7ffff34d5890, vksps_scaling=0x7ffff34d7f10, sps=0x7fffeb94d4c0) at libavcodec/vulkan_h264.c:140 #2 vk_h264_create_params (avctx=avctx@entry=0x7fffeaaf9c00, buf=buf@entry=0x7fffeb223708) at libavcodec/vulkan_h264.c:328 #3 0x00007ffff717cb4a in vk_h264_start_frame (avctx=0x7fffeaaf9c00, buffer=, size=) at libavcodec/vulkan_h264.c:384 #4 0x00007ffff6c34953 in decode_nal_units (buf_size=927876, buf=0x7ffff2e2c320 "", h=0x7ffff2f37140) at libavcodec/h264dec.c:655 #5 h264_decode_frame (avctx=, pict=0x7fffeb5034c0, got_frame=0x7ffff34fa14c, avpkt=) at libavcodec/h264dec.c:1015 #6 0x00007ffff6b126d2 in decode_simple_internal (discarded_samples=, frame=0x7fffeb5034c0, avctx=0x7fffeaaf9c00) at libavcodec/decode.c:287 #7 decode_simple_receive_frame (frame=, avctx=) at libavcodec/decode.c:533 #8 decode_receive_frame_internal (avctx=avctx@entry=0x7fffeaaf9c00, frame=0x7fffeb5034c0) at libavcodec/decode.c:553 #9 0x00007ffff6b13308 in avcodec_send_packet (avctx=avctx@entry=0x7fffeaaf9c00, avpkt=) at libavcodec/decode.c:641 #10 0x0000555555639a69 in init_avctx (vd=0x7ffff3449ef0) at ../video/decode/vd_lavc.c:775 #11 0x000055555563b04b in reinit (vd=0x7ffff3449ef0) at ../video/decode/vd_lavc.c:610 #12 control (vd=0x7ffff3449ef0, cmd=, arg=) at ../video/decode/vd_lavc.c:1286 #13 0x00005555555d1795 in mp_decoder_wrapper_control (d=, cmd=cmd@entry=VDCTRL_REINIT, arg=arg@entry=0x0) at ../filters/f_decoder_wrapper.c:355 #14 0x0000555555611fc1 in mp_option_change_callback (ctx=0x7ffff36c45c0, co=, flags=, self_update=) at ../player/command.c:6955 #15 0x00005555555ed2ba in force_self_notify_change_opt (self_notification=false, co=0x7ffff3628c00, config=0x7ffff7f04f20) at ../options/m_config_frontend.c:593 #16 m_config_set_option_raw (flags=, data=0x7ffff34fa360, co=0x7ffff3628c00, config=0x7ffff7f04f20) at ../options/m_config_frontend.c:652 #17 m_config_set_option_raw (config=0x7ffff7f04f20, co=0x7ffff3628c00, data=0x7ffff34fa360, flags=) at ../options/m_config_frontend.c:625 #18 0x00005555555ed6b1 in m_config_set_option_cli (config=config@entry=0x7ffff7f04f20, name=..., param=..., flags=flags@entry=4) at ../options/m_config_frontend.c:771 #19 0x00005555555ecf7c in m_config_set_profile (config=0x7ffff7f04f20, name=, flags=flags@entry=0) at ../options/m_config_frontend.c:1016 #20 0x00005555556038b1 in cmd_apply_profile (p=0x7fffeab06720) at ../player/command.c:6126 #21 0x000055555561128a in run_command (mpctx=0x7ffff36c45c0, cmd=0x7fffeb4df430, abort=, on_completion=0x5555555ff300 , on_completion_priv=0x7ffff34fa4a0) at ../player/command.c:4949 #22 0x00005555555ff231 in run_client_command (ctx=0x7ffff35cb590, cmd=0x7fffeb4df430, res=res@entry=0x0) at ../player/client.c:1137 #23 0x0000555555600a0b in mpv_command (ctx=, args=args@entry=0x7ffff34fa560) at ../player/client.c:1149 #24 0x0000555555672a6a in script_commandv (L=0x40080378) at ../player/lua.c:613 #25 0x00007ffff5b3c416 in ?? () from /lib/libluajit-5.1.so.2 #26 0x0000555555671146 in load_scripts (L=0x40080378) at ../player/lua.c:327 #27 0x00007ffff5b3c416 in ?? () from /lib/libluajit-5.1.so.2 #28 0x00007ffff5b895e8 in lua_pcall () from /lib/libluajit-5.1.so.2 #29 0x0000555555671f4f in run_lua (L=0x40080378) at ../player/lua.c:429 #30 0x00007ffff5b3c416 in ?? () from /lib/libluajit-5.1.so.2 #31 0x00007ffff5b8962c in lua_cpcall () from /lib/libluajit-5.1.so.2 #32 0x000055555566f8f6 in load_lua (args=) at ../player/lua.c:470 #33 0x0000555555621a85 in run_script (arg=arg@entry=0x7ffff35cbda0) at ../player/scripting.c:91 #34 0x0000555555621f69 in script_thread (p=0x7ffff35cbda0) at ../player/scripting.c:103 #35 0x00007ffff7fb55fe in ?? () from /lib/ld-musl-x86_64.so.1 #36 0x0000000000000000 in ?? () ```

I get a similar segfault with the example ffmpeg command linked here: https://trac.ffmpeg.org/wiki/HWAccelIntro#Vulkan

ffmpeg result ``` ~/test $ ffmpeg -init_hw_device "vulkan=vk:0" -hwaccel vulkan -hwaccel_output_format vulkan -i ./bird20.mkv -f null - -benchmark ffmpeg version git-2023-06-21-83b3ff7 Copyright (c) 2000-2023 the FFmpeg developers built with gcc 12.2.0 (GCC) configuration: --cc=cc --cxx=c++ --prefix=/usr --disable-stripping --disable-libxml2 --disable-static --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-libxcb-shape --disable-xlib --enable-gpl --enable-libass --enable-libdrm --enable-libglslang --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libxvid --enable-nonfree --enable-openssl --enable-shared --enable-version3 --x86asmexe=nasm libavutil 58. 13.101 / 58. 13.101 libavcodec 60. 21.100 / 60. 21.100 libavformat 60. 9.100 / 60. 9.100 libavdevice 60. 2.100 / 60. 2.100 libavfilter 9. 8.102 / 9. 8.102 libswscale 7. 3.100 / 7. 3.100 libswresample 4. 11.100 / 4. 11.100 libpostproc 57. 2.100 / 57. 2.100 Input #0, matroska,webm, from './bird20.mkv': Metadata: encoder : Haali Matroska Writer b0 Duration: 00:00:23.06, start: 0.000000, bitrate: 19031 kb/s Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1072 [SAR 1:1 DAR 120:67], 23.98 fps, 23.98 tbr, 20k tbn (default) Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native)) Press [q] to stop, [?] for help Segmentation fault ```

By similar I mean that it crashes in the same point: set_sps from libavcodec (ffmpeg).

ffmpeg stacktrace ``` #0 0x00007ffff7fc396a in memset () from /lib/ld-musl-x86_64.so.1 #1 0x00007ffff67d0adb in set_sps (vksps=0x7fffee172e30, vksps_vui=0x7fffee172930, vksps_vui_header=0x7fffee175130, vksps_scaling=0x7fffee1777b0, sps=0x7fffee19a500) at libavcodec/vulkan_h264.c:140 #2 vk_h264_create_params (avctx=avctx@entry=0x7fffee249400, buf=buf@entry=0x7fffedec00c8) at libavcodec/vulkan_h264.c:328 #3 0x00007ffff67d1b4a in vk_h264_start_frame (avctx=0x7fffee249400, buffer=, size=) at libavcodec/vulkan_h264.c:384 #4 0x00007ffff6289953 in decode_nal_units (buf_size=927876, buf=0x7fffedc5a244 "", h=0x7fffedb9f0c0) at libavcodec/h264dec.c:655 #5 h264_decode_frame (avctx=, pict=0x7fffedfdd000, got_frame=0x7fffedea3b10, avpkt=) at libavcodec/h264dec.c:1015 #6 0x00007ffff652c4a4 in frame_worker_thread (arg=0x7fffedea3a00) at libavcodec/pthread_frame.c:226 #7 0x00007ffff7fb55fe in ?? () from /lib/ld-musl-x86_64.so.1 #8 0x0000000000000000 in ?? () ```

Edit: In both instances, in the function set_sps, the vksps argument points to a completely zeroed out struct for some reason. I have no idea why it isn't populated. Perhaps it's a driver issue?

cyanreg commented 1 year ago

@Riteo I can't replicate with latest git master of ffmpeg. valgrind is clean too, so I'm not seeing a possibility of an issue. You should retest.

Riteo commented 1 year ago

@cyanreg still there :/

gdb log ``` (gdb) bt #0 0x00007ffff7fc396a in memset () from /lib/ld-musl-x86_64.so.1 #1 0x00007ffff67cfcab in set_sps (vksps=0x7fffedba1e30, vksps_vui=0x7fffedba1930, vksps_vui_header=0x7fffedba4130, vksps_scaling=0x7fffedba67b0, sps=0x7fffee2252c0) at libavcodec/vulkan_h264.c:140 #2 vk_h264_create_params (avctx=avctx@entry=0x7fffee14d780, buf=0x7fffee23ea88) at libavcodec/vulkan_h264.c:328 #3 0x00007ffff67d0e8f in vk_h264_start_frame (avctx=0x7fffee14d780, buffer=, size=) at libavcodec/vulkan_h264.c:383 #4 0x00007ffff6288a23 in decode_nal_units (buf_size=927876, buf=0x7fffedcaf0d4 "", h=0x7fffedbc9040) at libavcodec/h264dec.c:655 #5 h264_decode_frame (avctx=, pict=0x7fffee016240, got_frame=0x7fffede86a90, avpkt=) at libavcodec/h264dec.c:1015 #6 0x00007ffff652b654 in frame_worker_thread (arg=0x7fffede86980) at libavcodec/pthread_frame.c:226 #7 0x00007ffff7fb55fe in ?? () from /lib/ld-musl-x86_64.so.1 #8 0x0000000000000000 in ?? () (gdb) f 1 #1 0x00007ffff67cfcab in set_sps (vksps=0x7fffedba1e30, vksps_vui=0x7fffedba1930, vksps_vui_header=0x7fffedba4130, vksps_scaling=0x7fffedba67b0, sps=0x7fffee2252c0) at libavcodec/vulkan_h264.c:140 140 libavcodec/vulkan_h264.c: No such file or directory. (gdb) p *vksps $1 = {flags = {constraint_set0_flag = 0, constraint_set1_flag = 0, constraint_set2_flag = 0, constraint_set3_flag = 0, constraint_set4_flag = 0, constraint_set5_flag = 0, direct_8x8_inference_flag = 0, mb_adaptive_frame_field_flag = 0, frame_mbs_only_flag = 0, delta_pic_order_always_zero_flag = 0, separate_colour_plane_flag = 0, gaps_in_frame_num_value_allowed_flag = 0, qpprime_y_zero_transform_bypass_flag = 0, frame_cropping_flag = 0, seq_scaling_matrix_present_flag = 0, vui_parameters_present_flag = 0}, profile_idc = 0, level_idc = STD_VIDEO_H264_LEVEL_IDC_1_0, chroma_format_idc = STD_VIDEO_H264_CHROMA_FORMAT_IDC_MONOCHROME, seq_parameter_set_id = 0 '\000', bit_depth_luma_minus8 = 0 '\000', bit_depth_chroma_minus8 = 0 '\000', log2_max_frame_num_minus4 = 0 '\000', pic_order_cnt_type = STD_VIDEO_H264_POC_TYPE_0, offset_for_non_ref_pic = 0, offset_for_top_to_bottom_field = 0, log2_max_pic_order_cnt_lsb_minus4 = 0 '\000', num_ref_frames_in_pic_order_cnt_cycle = 0 '\000', max_num_ref_frames = 0 '\000', reserved1 = 0 '\000', pic_width_in_mbs_minus1 = 0, pic_height_in_map_units_minus1 = 0, frame_crop_left_offset = 0, frame_crop_right_offset = 0, frame_crop_top_offset = 0, frame_crop_bottom_offset = 0, reserved2 = 0, pOffsetForRefFrame = 0x0, pScalingLists = 0x0, pSequenceParameterSetVui = 0x0} ```

The all zeroed struct is the cause of the segfault. The weird thing is that vulkan video definitely works in all the other cases.

I'll try to investigate further to see what's setting this argument and why is it failing.

Edit: oh. It's apparently supposed to be empty as that function sets it. I'm not sure what's the cause of the segfault then. GDB simply points to the start of the function.

Edit2: just to be clear, then my assumption about the empty struct was wrong. I just supposed a normal null deference but that's clearly not the case.

cyanreg commented 1 year ago

Could you run gdb and run

set disassembly-flavor intel
disassemble

Or just break on set_sps and step through until it crashes. There's nothing weird about that file, it has a single SPS header, so it's not hitting the limit.

EDIT: ah, just read that you're on muslc You're on your own.

Riteo commented 1 year ago

@cyanreg

EDIT: ah, just read that you're on muslc You're on your own.

No worries, that's just the musl life lol. Thanks for trying to help!

Should I post the eventual solution here?

Riteo commented 1 year ago

Update: yep, it was a muslc thing. Basically the default stack was too small. That's why GDB gave very weird and changing results and valgrind kept reporting "Bad permissions for mapped region at address" even for a local array just declared a line before. How big are those StdVideoH264ScalingLists?

So, in the end, quick tip for musl users: ask the linker to set a preference for default stack size to something bigger than musl's small default by configuring ffmpeg with something like --extra-ldflags='-Wl,-z,stack-size=0x800000'. I chose a random size of 8 MBs but I have no idea how small it can be.

I think that I'll stop talking about this here because this is clearly not MPV related. Sorry for the inconvenience.