Skip to content

linux-v4l2: Use VIDIOC_S_FMT return values in vcam #12082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stephematician
Copy link
Contributor

@stephematician stephematician commented Apr 24, 2025

Description

When the virtual camera is opened, use the format returned by ioctl VIDIOC_S_FMT to; 1) confirm that the (YUYV) pixel format is expected, and; 2) configure the video scaling for the virtual camera.

This means that if the loopback device is constrained to a different size - then OBS studio will scale the output to the loopback device. If the pixel format of the loopback device is incorrect; the virtual camera will fail to open.

Motivation and Context

The current behaviour when a loopback device is constrained/fixed to a different size is shown in issue #12081.

There are two typical scenarios in which the loopback device will have a fixed format that could differ from OBS's output:

  1. The loopback device is already open by a reader; e.g. it is open in a browser, or some other application.
  2. The user fixed the format of the loopback device via v4l2loopback-ctl set-caps.

Ideally; some sensible cropping might be applied if the aspect ratio is not the same between the loopback device and OBS's output, but this hasn't been implemented here. Instead, the output is 'squeezed' into the aspect ratio of the loopback device.

How Has This Been Tested?

Built on Ubuntu 24.04 with v4l2loopback 0.14.0; then tested by following similar steps for reproduction in #12081

  1. Start loopback device and select a fixed format sudo modprobe v4l2loopback video_nr=10, then v4l2loopback-ctl set-caps /dev/video10 "YUYV:640x360".
  2. Open OBS studio with a scene, video output set to 1280x720, select 'Start virtual camera'.
  3. Play the virtual camera in ffplay /dev/video10

Here's the output scaled from 1280x720 (OBS) to 640x360 (loopback):

Screenshot at 2025-04-24 18-01-06

Types of changes

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Use the format returned by ioctl VIDIOC_S_FMT to; 1) confirm that the
pixel format is set, and; 2) configure the video scaling for the virtual
camera
@WizardCM WizardCM added Bug Fix Non-breaking change which fixes an issue Linux Affects Linux labels Apr 24, 2025
@RytoEX RytoEX requested a review from kkartaltepe May 1, 2025 21:07
@stephematician
Copy link
Contributor Author

stephematician commented May 20, 2025

Note: This fix also prevents distorted output to non-loopback devices if they have been (incorrectly) opened as the virtual output, e.g. #3929 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue Linux Affects Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

linux-v4l2: Distorted output when virtual camera has fixed format
2 participants