omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

screenrecording --with-webcam: overlay mpv segfaults with the Apple Silicon camera; the lavfi crop is the trigger (follow-up to #8480)

Open bodhiblues opened this issue 3 weeks ago • 2 comments

What happens

With omarchy-capture-screenrecording --with-webcam, the WebcamOverlay mpv crashes with SIGSEGV within seconds. The stack trace is the one in #8480: memcpy inside Mesa under pl_tex_upload. That's libvulkan_asahi.so with gpu-api=vulkan and libgallium with gpu-api=opengl.

#8480 was closed because Apple Silicon wasn't supported at the time. It still happens on Omarchy 4.5 with the official Mac packages, and I traced the trigger to the overlay's crop filter rather than the renderer.

Setup

  • MacBook Pro 14" M1 Pro (apple,j314s). FaceTime HD camera via apple-isp (/dev/video1), which offers only NV12.
  • omarchy 4.5.0-3, linux-aurora 7.2.11.aurora14, mesa-aurora / vulkan-aurora 26.3.0_devel.20261031, mpv 0.41.0, libplacebo 7.360.1-7.
  • To be upfront: this install was migrated in place from the omarchy-mac fork rather than made with the M Installer. Every package involved is the official [omarchy] Mac package, and the reproducer below only needs mpv and the camera.

Reproducer

This is the overlay's own invocation (start_webcam_overlay), varying one option at a time. Each variant was run 3 times for 150 frames.

mpv av://v4l2:/dev/video1 --profile=low-latency --untimed --no-cache \
    --demuxer-lavf-o=video_size=1280x720,framerate=30 --no-audio <variant>
Variant Result
no crop OK 3/3
--vf=lavfi=[crop=ih*8/9:ih] (as shipped) SIGSEGV 3/3, with both gpu-api=vulkan and gpu-api=opengl
the same crop on a 1280x720 NV12 test file instead of the camera OK 3/3 with both gpu-api=vulkan and gpu-api=opengl
--vf=lavfi=[crop=ih*8/9:ih] plus --vo=gpu (the #8480 proposal) OK 3/3
--vf=lavfi=[crop=ih*8/9:ih,format=yuv420p] OK 3/3
--video-crop=640x720+320+0 (no filter) OK 3/3

Likely cause (inference)

The lavfi crop filter doesn't copy the frame. It only moves the plane pointers into the V4L2 capture buffer, and on this camera those buffers are exactly frame-sized. The gpu-next upload then appears to read a full stride × height starting from the moved pointer, which runs past the end of the buffer. Decoded test-file frames have padding, so they survive. format=yuv420p (a copy) and --video-crop (no moved pointers) both avoid it. The underlying bug is probably in mpv or libplacebo's handling of cropped frames, but the overlay can avoid it cheaply.

Suggested fix

The script already knows the capture size, so it can do the same 8:9 centre crop with --video-crop. That's a GPU-side crop with no filter and no extra copy. It falls back to today's filter when no preferred size matched:

  local crop=('--vf=lavfi=[crop=ih*8/9:ih]')
  for resolution in "${preferred_resolutions[@]}"; do
    if echo "$available_formats" | grep -q "$resolution"; then
      capture_options="video_size=$resolution,$capture_options"
      local width=${resolution%x*} height=${resolution#*x}
      local crop_width=$((height * 8 / 9))
      crop=("--video-crop=${crop_width}x${height}+$(((width - crop_width) / 2))+0")
      break
    fi
  done

  mpv "av://v4l2:$WEBCAM_DEVICE" \
    --profile=low-latency --untimed --no-cache \
    --demuxer-lavf-o="$capture_options" \
    "${crop[@]}" \
    ...

That gives 320x360+160+0, 640x720+320+0 and 960x1080+480+0 for the three preferred sizes. --vo=gpu also works, but it switches the overlay to the older renderer on every machine.

Local workaround until then, in ~/.config/mpv/mpv.conf:

[webcam-overlay-crop-fix]
profile-cond=get("title") == "WebcamOverlay"
profile-restore=copy
vf=lavfi=[crop=ih*8/9:ih,format=yuv420p]

bodhiblues avatar Nov 06 '26 22:11 bodhiblues

I checked the report, #8480, and the current quattro webcam code. #19034, merged November 15 as 9599f76616825c99f78ff04cfa9512ecf899c0f7, replaced the overlay's mpv invocation with ffplay. The crop filter remains, but the reported mpv/libplacebo upload path is no longer used by the overlay. That source change does not establish that the Apple camera now works; I have not reproduced the crash or run tests.

Please recheck with a version containing that commit and report whether the ffplay overlay still crashes, including omarchy-debug --no-sudo --print output and a fresh backtrace if it does. GPT-6 High in Codex performed this source review. Classification remains unsettled: I classified the report as hardware compatibility, but the configured DeepSeek classifier returned no class. No full second review was requested, and no labels were applied; the classification is left for the maintainer.

omarchybot avatar Nov 19 '26 01:11 omarchybot

More data on the recheck asked for above, from different hardware: x86 ThinkPad X1 Carbon Gen 13 (Intel Lunar Lake, libvulkan_intel), Elgato Cam Link 4K over UVC (/dev/video4), omarchy 4.5.0-3, mpv 1:0.41.0-6, libplacebo 7.360.1-7, mesa/vulkan-intel 1:26.2.5-1, ffmpeg 2:9.0.2-2.

With the 4.5 mpv overlay, every recording stop left an mpv SIGSEGV core. The crashing vo thread has the same shape as this report: pl_queue_update → pl_upload_plane → pl_tex_upload → a read fault inside the Mesa driver. Here it doesn't need the crop. It is triggered by the overlay exiting (the SIGTERM from cleanup_webcam, and also an IPC quit or SIGINT). Sending SIGTERM to the shipped command after 4 s crashed about 60–100% of runs (6/6 in the first batch), with or without --vf=lavfi=[crop=…], --hwdec=no, or --gpu-api=opengl. ffmpeg logs video4linux2,v4l2: Some buffers are still owned by the caller on close. My reading, which I haven't confirmed in source: the v4l2 demuxer unmaps its mmap buffers on close while the VO still holds a zero-copy frame pointing into them. Consistent with that, adding a real pixel-format conversion (crop=…,format=nv12, which copies the frame out of those buffers) stopped that crash in every run I did (6/6, then 0 of these crashes in 20+ further exits). A second, less frequent mpv crash remained after that: a main-thread teardown jump through mpv's freed-memory poison 0xd3adb3ef, in about 10–20% of exits, on both Vulkan and OpenGL. I couldn't symbolize it, because Arch's debuginfod has no debuginfo for this mpv build.

With quattro's ffplay overlay (#19034), the same test with the same camera (exact start_webcam_overlay ffplay command including -vf 'crop=ih*8/9:ih', SIGTERM via pkill -f "WebcamOverlay" after 4 s) exited cleanly 8/8 (exit 123), with no cores. I can't speak to the Apple ISP camera, but on this machine the ffplay switch removes the crash.


Written by Claude (Anthropic) via the omp agent harness and posted with the account owner's approval. The exact model version is not verified.

k7cfo avatar Nov 27 '26 22:11 k7cfo