Skip to content

bug: linux-v4l2: virtual camera output distorted on a loopback device with a fixed format (upstream #12081) #212

Closed

Description

@rdoupe

Upstream OBS bug, reported by stephematician in obsproject/obs-studio#12081, with a fix in obsproject/obs-studio#12082 (open, not merged). Code unchanged in this fork.

Location

plugins/linux-v4l2/v4l2-output.c in try_connect(): the format VIDIOC_S_FMT returns is ignored (line 192). The video conversion is set to the OBS output size (lines 201-205) and each frame is written as width*height*2 bytes of that size (frame_size at :156, written in virtual_video at :309).

Class

Logic error: wrong frame geometry (corrupted output).

How it is reached

Start the virtual camera on a v4l2loopback device whose format is fixed (v4l2loopback-ctl set-caps, or keep_format=1) at a size other than the OBS output size. The device answers S_FMT with its own size, but OBS still writes frames of the output size: at 1280x720 into a 640x480 device, each 1280-pixel row fills two 640-pixel rows and the bottom half never arrives. Viewers see a distorted, interleaved picture.

Reproduced headlessly with the real linux-v4l2 plugin and a temporary loopback device fixed to YUYV 640x480, checking every pixel pair of a four-colour quadrant pattern read back through the device: master fails (top-left 10800/21600 match with green rows interleaved, bottom quadrants 0/21600); an unfixed device passes.

Proposed fix and failing test

Fix (obsproject/obs-studio#12082): take the scaling size and frame size from the format S_FMT returned, and skip a device that doesn't keep YUYV. The frame size stays width*height*2 (the packed YUY2 data OBS hands over) rather than the PR's bytesperline*height, so a driver that leaves bytesperline at 0 doesn't get 0-byte writes; for v4l2loopback the two are equal.

RED test (cmocka, test_vcam_format), with the decision moved into vcam-format.[ch] (vcam_format_negotiate(), behaviour unchanged): 3 of 4 fail today (fixed_smaller_device_gets_frames_of_its_size, fixed_larger_device_gets_frames_of_its_size, device_fixed_to_other_pixel_format_is_refused). With the fix all 4 pass, and the quadrant check passes with the device fixed to 640x480, 640x360 and 1920x1080, and unfixed.

Activity

  1. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_vcam_format (3 of 4 failing), format negotiation moved into vcam-format.[ch] with no behaviour change.
    2. GREEN: port linux-v4l2: Use VIDIOC_S_FMT return values in vcam obsproject/obs-studio#12082 by stephematician (use the format the device kept), credited.
      PR within the hour.
  2. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    @stephematician you reported this in obsproject/obs-studio#12081, so a heads-up: your fix from obsproject/obs-studio#12082 is merged here in obs-rust by #213 (credited as co-author), with a regression test.

    Two small differences from #12082: the frame size stays width*height*2 rather than bytesperline*height, so a driver that leaves bytesperline at 0 doesn't get 0-byte writes, and master's ioctl order is kept. Checked end to end against v4l2loopback 0.15.4 fixed to 640x480, 640x360 and 1920x1080 with a colour-quadrant pattern read back through the device.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR. If you spot anything off in the port, a reply here would help.

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