Repository navigation
Description
Operating System Info
Other
Other OS
NixOS 26.05, KDE Plasma 6.6 (Wayland), PipeWire 1.6.6, NVIDIA 595.71.05 (open), RTX 5090, Ryzen 9 9950X
OBS Studio Version
32.1.2
OBS Studio Version (Other)
nixpkgs build of 32.1.2. The code below is unchanged on master (a8b04ac).
OBS Studio Log URL
OBS Studio Crash Log URL
No response
Expected Behavior
Video from "Video Capture Device (PipeWire)" stays in sync with the audio. After a stall the source catches up to the newest frame, as "Video Capture Device (V4L2)" does with "Use Buffering" off.
Current Behavior
Every stall leaves the camera behind the audio for the rest of the session. Under sustained load the offset keeps growing until 30 frames are queued, then the queue is flushed and the picture jumps.
Cause:
process_video_asyncoutputs every frame withtimestamp = 0:obs-studio/plugins/linux-pipewire/pipewire.c
Lines 683 to 705 in a8b04ac
struct obs_source_frame out = {0}; if (!prepare_obs_frame(obs_pw_stream, &out)) { blog(LOG_ERROR, "[pipewire] Couldn't prepare frame"); goto done; } for (uint32_t i = 0; i < buffer->n_datas && i < MAX_AV_PLANES; i++) { out.data[i] = buffer->datas[i].data; if (out.data[i] == NULL) { blog(LOG_ERROR, "[pipewire] Failed to access data"); goto done; } } #ifdef DEBUG_PIPEWIRE blog(LOG_DEBUG, "[pipewire] Frame info: Format: %s, Planes: %u", get_video_format_name(out.format), buffer->n_datas); for (uint32_t i = 0; i < buffer->n_datas && i < MAX_AV_PLANES; i++) { blog(LOG_DEBUG, "[pipewire] Plane %u: Dataptr:%p, Linesize:%d", i, out.data[i], out.linesize[i]); } #endif obs_source_output_video(obs_pw_stream->source, &out); - The camera portal source never calls
obs_source_set_async_unbuffered(), so it stays buffered. - With
last_frame_tsstuck at 0,get_closest_frame()takes the oldest queued frame on every render tick:obs-studio/libobs/obs-source.c
Lines 4212 to 4217 in a8b04ac
static inline struct obs_source_frame *get_closest_frame(obs_source_t *source, uint64_t sys_time) { if (!source->async_frames.num) return NULL; if (!source->last_frame_ts || ready_async_frame(source, sys_time)) { - The async queue therefore behaves as a FIFO. It only drains when the camera delivers slower than the canvas renders, and it is flushed at
MAX_ASYNC_FRAMES:obs-studio/libobs/obs-source.c
Line 3540 in a8b04ac
#define MAX_ASYNC_FRAMES 30
With a 29.97 fps camera on a 30 fps canvas the backlog drains by one frame every ~33 s. A camera running at the canvas rate never drains it.
Measurement with a synthetic camera: 3840x2160 YUY2 at 29.97 fps written to v4l2loopback, with the frame number burned in as a barcode and read back from the recording. The PipeWire node was created with api.v4l2.source on that device, the same path a UVC camera takes. Load was stress-ng --cpu 32 --vm 4 --vm-bytes 2G plus a Cycles OptiX render. Canvas 30 fps, latency anchored to the recording start (±20 ms).
| Source | Idle | During 150 s of load | 90 s after the load |
|---|---|---|---|
| Video Capture Device (PipeWire) | 0–10 ms | rose to 220 ms and stayed | 73 ms, draining ~1 ms/s |
| Video Capture Device (V4L2), buffering off | 10–25 ms | 10–60 ms, spikes recover at once | 40–60 ms |
OBS logged no lagged frames in these runs; the stalls came from the delivery side (the synthetic camera stalled up to ~200 ms and then delivered a burst). In real sessions, graphics thread stalls feed the same queue (up to 1153 ms in the attached log).
Steps to Reproduce
- Add "Video Capture Device (PipeWire)" for a UVC camera or capture card (here a UGREEN 35871, 3840x2160 YUY2 at 30 fps).
- Record while the system is under heavy CPU and GPU load, or cause any render stall of two or more frames.
- Compare video and audio (clap or frame counter): after the stall the video stays behind.
Anything else we should know?
Possible fixes: set out.timestamp (from the buffer's spa_meta_header pts where available, otherwise os_gettime_ns() at dequeue), and/or make the source unbuffered or expose "Use Buffering" as the V4L2 source does. Moving the same device to the V4L2 source with buffering off removed the drift on this machine.
Related: #13971 (startup crash in the same camera portal code).
Activity