mpv-player / mpv

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

Crash with hwdec vaapi on intel #15030

Open darkblaze69 opened 2 hours ago

darkblaze69 commented 2 hours ago

mpv Information

mpv v0.39.0 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Sep 23 2024 17:46:22
libplacebo version: v7.349.0
FFmpeg version: n7.0.2
FFmpeg library versions:
   libavcodec      61.3.100
   libavdevice     61.1.100
   libavfilter     10.1.100
   libavformat     61.1.100
   libavutil       59.8.100
   libswresample   5.1.100
   libswscale      8.1.100

Other Information

- Linux version: Arch Linux
- Kernel Version: Linux 6.12.0-rc2-1-mainline #1 SMP PREEMPT_DYNAMIC Mon, 07 Oct 2024 06:05:31 +0000 x86_64 GNU/Linux
- GPU Model: Intel Corporation Meteor Lake-P [Intel Arc Graphics]
- Mesa/GPU Driver Version: Mesa 24.2.4-arch1.1
- Window Manager and Version: mutter 47.0
- Source mpv: official Arch package
- Introduced in version: [6797f543782d29561ec7b28163ec82e9a4d79318] hwdec/vaapi: additionally probe hwupload format conversions

Reproduction Steps

mpv --hwdec=vaapi --fs ~/Videos/bbb_sunflower_2160p_60fps_normal.mp4

Downgrading to 0.38 allows playing normally.

Bisected to [6797f543782d29561ec7b28163ec82e9a4d79318] hwdec/vaapi: additionally probe hwupload format conversions

Video trying to play:

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L5.1
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 10 min 34 s
Bit rate                                 : 8 000 kb/s
Maximum bit rate                         : 35.1 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 60.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.016
Stream size                              : 605 MiB (94%)
Writing library                          : x264 core 120
Encoding settings                        : cabac=1 / ref=4 / deblock=1:1:1 / analyse=0x3:0x133 / me=tesa / subme=11 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=1 / me_range=24 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=0 / chroma_qp_offset=-2 / threads=12 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=16 / b_pyramid=2 / b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=60 / rc=2pass / mbtree=1 / bitrate=8000 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / aq=1:0.60
Encoded date                             : 2013-12-17 16:40:26 UTC
Tagged date                              : 2013-12-17 16:40:29 UTC
Codec configuration box                  : avcC

Expected Behavior

playing video

Actual Behavior

crash

Log File

output.txt

gdb.log

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

llyyr commented 2 hours ago

Could you report this to Mesa? Your GPU is extremely new, so there's a high chance this will get fixed.

Probably duplicate of #14956 but from different vendor. The crash is different, but still I don't think mpv is doing anything wrong here

darkblaze69 commented 2 hours ago

What should I report there ? which relevant lines form the logs to provide?

Also note it seems a regression with specific mpv commit which definitely flips normal > crash behavior.

kasper93 commented 2 hours ago

Also note it seems a regression with specific mpv commit which definitely flips normal > crash behavior.

Yes, we are trying to upload more formats now during the probing phase. This doesn't change the fact that it shouldn't crash. At most, it should print an error and move on. So, it’s not mpv’s fault for crashing. In retrospect, it may be a bit tricky to handle all the failing cases with unusual formats and various hardware/driver bugs. We might need to implement some workarounds, but to be clear, this should be fixed upstream.

We will react as necessary.

Dudemanguy commented 2 hours ago

We could try probing something more common if possible as a workaround I suppose. @darkblaze69: does it still crash if you force it to NV12?

diff --git a/video/out/hwdec/hwdec_vaapi.c b/video/out/hwdec/hwdec_vaapi.c
index e8d4f159db..99fb8c57ae 100644
--- a/video/out/hwdec/hwdec_vaapi.c
+++ b/video/out/hwdec/hwdec_vaapi.c
@@ -456,7 +456,7 @@ static void try_format_upload(struct ra_hwdec *hw, enum AVPixelFormat pixfmt)

     AVBufferRef *hw_pool = av_hwframe_ctx_alloc(p->ctx->av_device_ref);
     mp_update_av_hw_frames_pool(&hw_pool, p->ctx->av_device_ref, IMGFMT_VAAPI,
-                                p->formats[0], src->w, src->h, false);
+                                IMGFMT_NV12, src->w, src->h, false);

     struct mp_image *dst = mp_av_pool_image_hw_upload(hw_pool, src);
llyyr commented 2 hours ago

I'm also curious if increasing the image size has any effect. Try this as well

diff --git a/video/out/hwdec/hwdec_vaapi.c b/video/out/hwdec/hwdec_vaapi.c
index e8d4f159db28..39b0eda3f3f2 100644
--- a/video/out/hwdec/hwdec_vaapi.c
+++ b/video/out/hwdec/hwdec_vaapi.c
@@ -450,7 +450,7 @@ static void try_format_upload(struct ra_hwdec *hw, enum AVPixelFormat pixfmt)
     if (!p->formats || !p->formats[0])
         return;

-    struct mp_image *src = mp_image_alloc(mp_fmt, 2, 2);
+    struct mp_image *src = mp_image_alloc(mp_fmt, 32, 32);
     if (!src)
         return;
kasper93 commented 2 hours ago

We could try probing something more common if possible as a workaround I suppose. @darkblaze69: does it still crash if you force it to NV12?

I would put the try_format_upload into select_format or after it and check only the formats we are trying to use and retry select_format if try_format_upload fails, until we find something working or have no more formats to check. This lazy change would allow to avoid probing formats that we would never use in practice.

I'm also curious if increasing the image size has any effect. Try this as well

Like said on IRC some time ago, I think 16 or 64 should be safe here in other place we use 128. Though if 2x2 doesn't work that means we either don't align stride correctly for images or it is just a bug in driver.

I know it is little bit unfortunate we have to deal with this.

philipl commented 1 hour ago

Note thay this needs to be reported to Intel-media-driver rather than mesa. There are often rough edges for new hardware. I had to report a bunch of problems for Gen12.

darkblaze69 commented 1 hour ago

Tried both patches combined and separate, no luck.

Dudemanguy commented 1 hour ago

I would put the try_format_upload into select_format or after it and check only the formats we are trying to use and retry select_format if try_format_upload fails

I guess this is the way to go although it might get messy with the VO and hwdec layers.

kasper93 commented 51 minutes ago

I would put the try_format_upload into select_format or after it and check only the formats we are trying to use and retry select_format if try_format_upload fails

I guess this is the way to go although it might get messy with the VO and hwdec layers.

We can test only formats from upload formats list, the target formats is expected to work.