Skip to content

bug: linux-pipewire: cameras sending NV12 show green or crash (upstream #13823) #390

Closed

Description

@rdoupe

Upstream OBS bug, reported by EberhartLeberhart in obsproject/obs-studio#13823 (Linux Mint 22 and Fedora 44, OBS 32.2.2 and 30.2.3, an IPU3 camera through libcamera). A "Video Capture Device (PipeWire)" source on a camera that sends NV12 shows the picture green, in three horizontal bands, at a fraction of the camera's frame rate. theCarlG hit the same code as a crash in obsproject/obs-studio#14002 (Arch, OBS 32.2.2, PipeWire 1.6.9): OBS crashes as soon as the camera streams, with an Elgato Facecam Pro, a Sony A6700 and a Sony A7V. Both posted a patch; the issue was closed on 2026-10-01 and the PR on 2026-10-07, neither merged. The code is unchanged upstream and in this fork.

Location

  • plugins/linux-pipewire/pipewire.c line 663, prepare_obs_frame(): the frame gets one line size, width * bpp, and formats.c lines 74-80 give NV12 a bpp of 2. NV12's luma rows are width bytes.
  • Same file, process_video_async() lines 694-700: one data pointer per PipeWire data block, and no line size for any plane after the first. Cameras send NV12 with both planes in one block (PipeWire's V4L2 and libcamera plugins both do), so the chroma plane gets no pointer and line size 0. The stride and offset the producer writes in the buffer's chunk are ignored for every format.

libobs then copies the frame (copy_frame_data(), libobs/obs-source.c line 3463) with a luma line size of twice the real one, so it reads twice the luma plane, past the end of the buffer, and copies nothing into the chroma plane.

Class

Wrong picture and an out-of-bounds read. The chroma plane stays uninitialised (green), the luma rows double up (the bands), and the read past the buffer can run off its mapping and crash OBS (theCarlG, NV12 1920x1080 at 60 fps). The reporter also measured 11.8 instead of 30 fps and 81% instead of 8% CPU.

How it is reached

  1. Have a camera that offers NV12 through PipeWire (some UVC webcams such as the Elgato Facecam Pro, cameras in UVC streaming mode such as the Sony A6700, laptop cameras behind an Intel IPU through libcamera).
  2. Add a "Video Capture Device (PipeWire)" source, select the camera and NV12.

The preview is green and banded, or OBS crashes. YUYV on the same camera is fine.

Reproduced end to end here: a producer stream on a private PipeWire daemon offering only NV12 (one block; one block with padded rows; one block per plane), the camera source's stream code connected as the camera portal connects it, and the output read back. Every layout comes out green: (0, 135, 0) where the picture is (200, 40, 40).

Upstream work

Proposed fix and failing test

Fix (plugins/linux-pipewire only):

  • The plane setup of process_video_async() moves into a small helper, obs_pw_frame_layout() in frame-layout.[ch], with no stream state so it can be tested without PipeWire.
  • NV12 in one block: luma at the chunk offset, chroma right after it, both with the chunk stride. One block per plane: each plane from its own block, offset and stride. Every format honours the chunk stride and offset; without a stride, rows are rounded up to 4 bytes as before.
  • The chunk is written by the producer: a buffer whose chunk lies outside the mapped block, whose stride is shorter than a row, or that does not hold every row of every plane is dropped (one warning per stream) instead of being read out of bounds.

RED tests:

  • test_pipewire_frame_layout (cmocka, Linux, no daemon, no display, runs in CI): fake buffers the way producers send them. 7 of 8 cases fail today; the guard (tightly packed YUY2 and RGBA) passes.
  • test_pipewire_camera_nv12 (cmocka, Linux, private PipeWire and private Xvfb, skips without them): the end-to-end case above. 3 of 3 fail today, green output.

Activity

  1. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_pipewire_frame_layout (7 of 8 failing, no daemon or display, runs in CI) checks the planes OBS builds from a PipeWire buffer; test_pipewire_camera_nv12 (3 of 3 failing: green) runs an NV12 producer on a private PipeWire into the camera's stream code and reads the colours back.
    2. GREEN: set NV12's chroma plane from the chunk's stride and offset, one or two blocks; drop frames whose chunk doesn't fit (port of linux-pipewire: Fix crash with NV12 camera frames obsproject/obs-studio#14002 with fixes).
      PR today.
  2. added a commit that references this issue on Oct 12, 2026
    623b605
  3. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    @EberhartLeberhart you reported this in obsproject/obs-studio#13823, so a heads-up: it's fixed here in obs-rust by #391, merged today with a regression test.

    Cause: when a camera sends NV12 through PipeWire, OBS gave the frame a single line size of width x 2 bytes and never set the chroma plane at all, because cameras send NV12's two planes in one buffer. libobs then copied twice the luma plane (reading past the buffer) and nothing into chroma: the green picture with bands you saw, and with some cameras a crash, which theCarlG hit with an Elgato Facecam Pro and Sony A6700/A7V. This builds on theCarlG's upstream patch, obsproject/obs-studio#14002, with the two of you credited as co-authors. Now OBS lays out NV12's planes from the buffer's own stride and offset, whether they come in one block or two, honours the stride and offset for every format, and drops (with one warning) a frame whose buffer is too small instead of reading past it. The test sends NV12 from a private PipeWire stream through the camera code and checks the colours: before, the picture came out green; now it matches within 1/255.

    Not covered: no physical camera was used, and the camera portal itself was bypassed in the end-to-end test. I420-only cameras are a separate gap.

    Workaround on stock OBS: pick a YUY2 or MJPEG format for the camera in the source's properties, if it offers one.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you try it, a short reply here on whether your camera shows a clean picture would really help.

  4. EberhartLeberhart commented on Oct 14, 2026

    @EberhartLeberhart
    Contributor

    Tested on real hardware. Short version: the colours are correct, and what remains is a different bug.

    What I did

    I did not build obs-rust itself (I am on Linux Mint 22, and the AUR package does not help me there). Instead I took frame-layout.c, frame-layout.h and your changes to pipewire.c from #391 and applied them to my own build of upstream 32.2.2 — the same build I used for the measurements in obsproject/obs-studio#13823. So this is your plane layout on stock 32.2.2, not the full fork.

    Hardware: Surface Pro 5, OV8865 (rear) and OV5693 (front) behind an Intel IPU3, through libcamera 0.2.0 and PipeWire 1.0.5, kernel 6.19.8-surface-3.

    Result

    The picture is correct. No green, no bands — the same as with my own patch from #13823. Negotiated format NV12, both at 640x480 and 1280x720.

    So your layout works on hardware that sends NV12 in a single block, which is what I could not confirm for you from the test harness alone.

    What is not fixed, and is not yours

    The stream still drops periodically, and the log shows why:

    [pipewire] Negotiated format: NV12 640x480 30/1
    [pipewire] Stream state: "streaming" (error: none)
    [camera-portal] Selected format for '...CAMR'
    [pipewire] Renegotiating stream
    error: [pipewire] Error res:-32 (Broken pipe): connection error
    [pipewire] Stream state: "unconnected" (error: connection error)
    

    The format-selected callback in camera-portal.c fires again on an already streaming stream and renegotiates, which kills it. At 640x480 that shows as stuttering, at 1280x720 the picture freezes. This is identical with your patch, with mine, and with none — it predates both and looks like the same thing as obsproject/obs-studio#10180.

    One more thing in the log

    On shutdown:

    'loop->recurse > 0' failed at ../src/pipewire/thread-loop.c:426 pw_thread_loop_wait()
    *** impl_ext_end_proxy called from wrong context, check thread and locking
    

    This was already in my logs in August, before any of these patches, so I do not think it is related — mentioning it only so it is on record.

    Note on my own camera

    The front sensor delivers a mean luminance of 0 at 640x480 through cam --capture as well, with no OBS involved, so a black picture from that one is a sensor-side issue on this device, not a rendering problem.

    Thanks for picking this up and for the credit.

  5. rdoupe commented on Oct 15, 2026

    @rdoupe
    CollaboratorAuthor

    Thank you for testing this on the Surface. A hardware result was the part we could not get from the test harness, and it is good to know the plane layout holds on a camera that sends NV12 in one block.

    You are right that the drop is a separate bug, and it is not the NV12 change. We tracked it down and reproduced it in the current release (0.1.0-beta.20261014) with a virtual camera:

    • Whenever the camera's Properties window opens or reloads, OBS runs the source's format and framerate callbacks again. While the window is open it reloads every time any PipeWire node appears or disappears, OBS's own capture stream included. That is the Selected format line you see on a stream that is already streaming.
    • Those callbacks ask the running stream for the selected size and framerate again. If the stream was started without the framerate that is in the settings, OBS renegotiates it even when it already runs at exactly that framerate. One case is a framerate set while the camera was streaming. Another is a stream restarted after the camera came back, which also started without the framerate you picked.
    • A V4L2 camera survives that renegotiation. libcamera cannot reconfigure a camera while it streams (the libcamera log in Changing camera resolution breaks the camera portal obsproject/obs-studio#10399 says the same: Camera in Running state trying configure()). On your IPU3 the renegotiation is where the stream breaks.

    I think obsproject/obs-studio#10399 is the closer upstream match. #10180 turned out to be a camera that offered no supported format.

    The fix is up as #820 (issue #819). OBS skips the renegotiation when the stream already runs at the requested size and framerate, and it keeps the framerate you picked for any stream it starts later. Real changes still renegotiate as before. With it, the same scenario no longer renegotiates. It is two small hunks, in camera-portal.c (framerate_selected()) and in pipewire.c (obs_pipewire_stream_set_framerate() / _set_resolution()), so it applies to your 32.2.2 build the same way as before. We could not test it on a libcamera camera, so your result on the Surface would be the real test. Once it is merged, it will be in the next release after 0.1.0-beta.20261014: https://github.com/obs-rust/obs-studio/releases

    On the shutdown messages: impl_ext_end_proxy called from wrong context is what our #513 fixed (camera devices were destroyed without the PipeWire loop lock). That fix is in our releases since 0.1.0-beta.20261013 but not in stock 32.2.2. The 'loop->recurse > 0' assertion comes from OBS calling pw_thread_loop_wait() at teardown without holding the loop lock. Newer PipeWire (1.6, which we test with) no longer checks for this, so neither message showed up on quit here. We will look at that one separately.

  6. EberhartLeberhart commented on Oct 15, 2026

    @EberhartLeberhart
    Contributor

    Tested on real libcamera hardware: Surface Pro 5 (Intel IPU3, ipu3-cio2 + ipu3-imgu, ov8865 rear + ov5693 front), libcamera 0.2.0, PipeWire 1.0.5, kernel 6.19.8, OBS 32.2.2 built from source.

    Short version: this patch does not fix the case I run into, and I think the reason is worth writing down — the defect is one branch away from where you looked.

    1. With #820 applied, the stream still dies

    Add a camera source, let it start, then pick any other resolution from the format dropdown:

    [camera-portal] Selected format for '...I2C3.CAMR'
    resolution: negotiated=640x480 requested=240x160
    [pipewire] Renegotiating stream
    error: [pipewire] Error id:0 seq:282 res:-32 (broken pipe): connection error
    [pipewire] Stream state: "unconnected" (error: connection error)
    

    I first assumed something was re-asserting a stale value, so I instrumented format_selected() with backtrace() to see who asks. For the call that kills the stream:

    WidgetInfo::ControlChanged()                 properties-view.cpp:2137
      <- QComboBox::currentIndexChanged
      <- QComboBoxPrivateContainer::itemSelected
      <- QApplicationPrivate::sendMouseEvent
    

    A real mouse click on the format combo, with a genuinely different value. So running_at_it cannot help here: nothing is asking for the size it already has. I verified this deliberately — streaming at 640x480, then picking 240x160 by hand — and it breaks every time.

    Side note from the same traces, because it surprised me: on a fresh source the call that starts the stream is not a user action either. It comes from

    OBSPropertiesView::RefreshProperties -> AddProperty -> AddList
    

    which ends in

    /* trigger a settings update if the index was not found */
    if (count && idx == -1) {
            info->ControlChanged();
    }
    

    The saved format is still empty, so it is not in the list, so OBS commits list entry 0 on its own. That it happens to be a sane resolution is luck.

    2. The defect

    format_selected() already knows the right way to apply a change — it just does not use it for the resolution:

    if (!camera_source->obs_pw_stream || camera_source->restart_stream ||
        last_subtype != camera_source->subtype ||
        last_format != camera_source->format.spa_format) {
            camera_source->restart_stream = false;
            stream_camera(camera_source);            /* destroy + recreate */
    } else if (camera_source->obs_pw_stream) {
            obs_pipewire_stream_set_resolution(...); /* renegotiate */
    }
    

    A subtype or pixel-format change destroys and recreates the stream. A resolution change renegotiates. Cameras behind libcamera cannot be reconfigured while they deliver, so the renegotiation path always ends in -EPIPE.

    3. The change

    Treat the resolution exactly like the pixel format:

     	enum spa_video_format last_format = camera_source->format.spa_format;
    +	struct spa_rectangle last_resolution = camera_source->resolution.rect;
     	bool has_framerates;
    @@
    +	/* A resolution change cannot be negotiated on a running stream:
    +	 * libcamera cannot reconfigure a camera while it delivers, and
    +	 * PipeWire aborts with -EPIPE. Destroy and recreate instead, just
    +	 * like for subtype and pixel format. */
     	if (!camera_source->obs_pw_stream || camera_source->restart_stream || last_subtype != camera_source->subtype ||
    -	    last_format != camera_source->format.spa_format) {
    +	    last_format != camera_source->format.spa_format ||
    +	    last_resolution.width != camera_source->resolution.rect.width ||
    +	    last_resolution.height != camera_source->resolution.rect.height) {
     		camera_source->restart_stream = false;
     		stream_camera(camera_source);
    -	} else if (camera_source->obs_pw_stream) {
    -		obs_pipewire_stream_set_resolution(camera_source->obs_pw_stream, &camera_source->resolution.rect);
     	}
    

    Measured with a pristine pipewire.c (only the NV12 frame-layout work from #391 applied) and with none of #820 in the tree:

    CAMF 640x480 streaming
      -> 1280x720:            paused -> unconnected -> new stream -> 1280x720 streaming
      -> switch CAMF -> CAMR: paused -> unconnected -> new stream -> 1280x720 streaming
    

    No renegotiation, no -EPIPE, repeatable, both cameras. The front camera (ov5693), which until now only ever produced black frames in OBS, works too.

    4. What I could not test

    • obs_pipewire_stream_set_framerate() has the identical structure and should break the same way on a libcamera camera that offers several framerates. I cannot exercise it here: framerate_list() returns nothing for these cameras (has_framerates == 0, measured), so framerate_selected() is never reached. If you have hardware that reaches it, that path probably wants the same restart treatment rather than a guard.

    • Screen and window capture, which share obs_pipewire_stream_set_resolution(). Renegotiation is presumably fine there, which is why I would keep this change in camera-portal.c instead of touching pipewire.c.

    5. Two side observations, each its own small thing

    • The format list contains the camera's default format twice — once as entry 0 and again at its sorted position (both 640x480 here). The dropdown shows a visible duplicate.

    • Every format label advertises 30 FPS, but framerate_list() finds no framerates at all for the same format and size.

    For completeness, so nobody chases it as an OBS problem: on this hardware the preview stutters at the small resolutions, and that is not OBS. Measured with cam, outside OBS and outside PipeWire:

    requested delivered
    1280x720 29.9 fps
    960x540 29.9 fps
    800x600 30.0 fps
    640x480 90.1 fps
    320x240 90.9 fps
    160x120 89.9 fps

    Below 800x600 the IPU3 pipeline handler picks the sensor's binned mode, which runs at 90 fps, and the negotiated 30/1 is not enforced anywhere down the stack. OBS then receives three times the frames it agreed to, plays them in order and skips ahead when its queue fills — which is exactly what the stutter looks like. Unrelated to this patch, and nothing OBS can fix.

    Happy to open this wherever you prefer, or to leave it entirely with you — your work on #391 and #820 is the only reason we picked this up again.

  7. rdoupe commented on Oct 15, 2026

    @rdoupe
    CollaboratorAuthor

    Thank you for this, and for the backtrace. You're right, and our last reply was wrong about your case. #820 only stops OBS from renegotiating a stream that already has the size it asks for. A real resolution change still goes down the renegotiation branch you pointed at, so #820 does nothing for it.

    We reproduced it here with our current release (0.1.0-beta.20261014) against a PipeWire 1.0.5 daemon with its libcamera plugin and libcamera's virtual camera. Switching 640x480 to 320x240 gives your exact lines: Renegotiating stream, then res:-32 (Broken pipe) and unconnected. libcamera logs Camera in Running state trying configure(), and on this setup the 1.0.5 daemon then crashes in the plugin. Current master behaves the same. With your change in format_selected(), the old stream closes, a new one starts at 320x240, and switching back and forth repeatedly gives no errors.

    PipeWire's libcamera plugin has stopped the camera before reconfiguring it since 1.4.9, so this hits 1.0.x (Ubuntu 24.04, Mint 22) and early 1.4.x (Debian 13 ships 1.4.2).

    On framerates: the same in-place path also crashed the 1.0.5 daemon when a framerate saved earlier had to be dropped because the camera lists none, which is the has_framerates == 0 case you measured. That now happens as part of the same restart. framerate_selected() is left alone, since these cameras never reach it.

    We'll leave it with us, as you offered. We'll open an issue and a PR built on your change, credited to you, with a regression test. We'll post the links here. We won't call it fixed until it runs on your Surface. A test there once it's up would be the real check. The duplicate default entry in the format list and the "30 FPS" labels are noted as separate items.

  8. rdoupe commented on Oct 16, 2026

    @rdoupe
    CollaboratorAuthor

    As promised, here are the links:

    The PR adds one thing to your change. When the camera lists no framerates, a framerate saved earlier is now dropped as part of the same restart, instead of with obs_pipewire_stream_set_framerate(NULL) on the running stream, which crashed the 1.0.5 daemon here too. pipewire.c and framerate_selected() are unchanged.

    The change is only in plugins/linux-pipewire/camera-portal.c, so it should apply to your 32.2.2 build the same way your patch did. The diff is in the PR's second commit.

    We've only run this against libcamera's virtual camera, not real hardware. The PR says Refs, not Fixes, so #933 stays open until it runs on your Surface. When you have time, please try a resolution change on both cameras, and a camera that had a framerate saved before. Your result there is what decides it.

  9. zackees commented on Oct 16, 2026

    @zackees
    Member

    @EberhartLeberhart thank you for the real-hardware results and the backtrace. Where things stand:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions