Repository navigation
Description
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.cline 663,prepare_obs_frame(): the frame gets one line size,width * bpp, andformats.clines 74-80 give NV12 abppof 2. NV12's luma rows arewidthbytes.- 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
- 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).
- 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
- linux-pipewire: Fix crash with NV12 camera frames obsproject/obs-studio#14002 by theCarlG: sets up both NV12 planes from the chunk stride and drops buffers too small for the frame. Closed upstream without review. Ported here with credit.
- The patch in PipeWire camera source: out.linesize[i] never set for planes > 0 — NV12 renders green obsproject/obs-studio#13823 by EberhartLeberhart: takes each plane's line size from its chunk stride and derives the chroma pointer for one-block NV12; tested on the reporter's hardware.
- Not part of this issue, separate causes: linux-pipewire: Fix use-after-free in log message obsproject/obs-studio#13698 (pobrn, open: unplugging a PipeWire camera logs a freed string) and Flatpak: Camera portal fails with 'no more input formats' for I420-only V4L2 devices, but direct V4L2 source works obsproject/obs-studio#13744 (Owlock: I420-only cameras cannot connect, I420 is not in the format table).
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()inframe-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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 12, 2026
Claiming: this issue.
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.PR today.
linux-pipewire: Fix NV12 camera frames
linux-pipewire: Fix NV12 camera frames (obs-rust#391)
rdoupe commentedon Oct 12, 2026
@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-gitin the AUR.If you try it, a short reply here on whether your camera shows a clean picture would really help.
EberhartLeberhart commentedon Oct 14, 2026
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.hand your changes topipewire.cfrom #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:
The format-selected callback in
camera-portal.cfires 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:
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 --captureas 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.
rdoupe commentedon Oct 15, 2026
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:
Selected formatline you see on a stream that is already streaming.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 inpipewire.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/releasesOn the shutdown messages:
impl_ext_end_proxy called from wrong contextis 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 callingpw_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.test/cmocka: Add failing test for renegotiating a streaming PipeWire …
linux-pipewire: Do not renegotiate a camera stream for the format it …
EberhartLeberhart commentedon Oct 15, 2026
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:
I first assumed something was re-asserting a stale value, so I instrumented
format_selected()withbacktrace()to see who asks. For the call that kills the stream:A real mouse click on the format combo, with a genuinely different value. So
running_at_itcannot 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
which ends in
The saved
formatis 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: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:
Measured with a pristine
pipewire.c(only the NV12 frame-layout work from #391 applied) and with none of #820 in the tree: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), soframerate_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 incamera-portal.cinstead of touchingpipewire.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
640x480here). The dropdown shows a visible duplicate.Every format label advertises
30 FPS, butframerate_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: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.
rdoupe commentedon Oct 15, 2026
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, thenres:-32 (Broken pipe)andunconnected. libcamera logsCamera 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 informat_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 == 0case 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.
rdoupe commentedon Oct 16, 2026
As promised, here are the links:
format_selected()change and credited to you, with a regression test.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.candframerate_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.
test/cmocka: Add failing test for a PipeWire camera resolution change
linux-pipewire: Restart a camera stream for a new resolution
linux-pipewire: Restart a camera stream for a new resolution (obs-rus…
zackees commentedon Oct 16, 2026
@EberhartLeberhart thank you for the real-hardware results and the backtrace. Where things stand:
format_selected()change and credited to you, is merged: linux-pipewire: Restart a camera stream for a new resolution #934 (tracked in bug: linux-pipewire: picking another resolution for a running PipeWire camera renegotiates it in place (libcamera cameras on PipeWire before 1.4.9 lose the stream; upstream #10399) #933). Nothing in your report has been left unhandled. bug: linux-pipewire: picking another resolution for a running PipeWire camera renegotiates it in place (libcamera cameras on PipeWire before 1.4.9 lose the stream; upstream #10399) #933 stays open until it has run on a real IPU3 camera.