Repository navigation
Description
Upstream OBS bug, reported by vpzomtrrfrt in obsproject/obs-studio#11633 (Gentoo, OBS 30.2.3). The camera controls of a Video Capture Device (V4L2), such as "Zoom, Absolute", focus, exposure or brightness, are saved with the source but are not applied again: after closing OBS, replugging the camera and reopening OBS, the camera is back on its driver's values until the user moves the slider again. Earlier reports were folded into obsproject/obs-studio#3092 (ifohancroft, 2020; thadeupenna, EduardoRFS and Staacks there too, Staacks for HDMI grabbers that start with the wrong saturation), obsproject/obs-studio#3865 (janakelarsson: settings lost when the computer restarts or the device changes) and obsproject/obs-studio#5779 (desmondw and Pablomx2: settings revert when unplugged). All three were closed without a fix. For DirectShow on Windows, obsproject/obs-studio#5480 restored the device's settings in OBS 28.0 and was reverted in 28.0.1 because it caused issues with some capture cards; Linux never had it. The OBS forum has more (threads 62823, 182173 and 118096). The code has not changed in this fork.
Location
plugins/linux-v4l2/v4l2-controls.cv4l2_control_changed()(lines 35-69) is the only place that writes a control (VIDIOC_S_CTRL, line 62). It is the property's modified callback, so it runs only when the user changes the control in the Properties window.plugins/linux-v4l2/v4l2-input.cv4l2_create()/v4l2_update()(lines 1059-1121) andv4l2_init()(line 914), which the reconnect handlerdevice_added()(line 763) calls, open the camera and set the input, format and frame rate, but never write the saved controls.
Class
Settings lost: values the user set and OBS saved are not applied when OBS starts, when the camera is replugged or comes back from suspend, or when a script or obs-websocket (SetInputSettings) changes them. The Properties window then shows the saved value while the camera uses another one.
How it is reached
- Set "Zoom, Absolute" (or any control) in the source's properties, close OBS, replug the camera (or reboot), start OBS: the camera is on the driver's value.
- Replug the camera while OBS runs: OBS reopens it, on the driver's values.
- Change a control with obs-websocket
SetInputSettingsor a script'sobs_source_update(): the setting changes, the camera does not.
Reproduced headlessly with the real v4l2-input.c and v4l2-controls.c against a fake libv4l2 that behaves like a UVC webcam and records every control write: creating the source with saved controls, replugging it and updating it from a script write no control at all.
Upstream work
obsproject/obs-studio#13279 by GrantAbell (open since 2026-04, no review) adds v4l2_apply_controls(), which writes the controls that have a user value and differ from the device, and calls it from v4l2_update(). Port it with credit, with these changes, each with a failing case against the PR as is:
- the reconnect path (
device_added()->v4l2_init()) does not go throughv4l2_update(), so a replugged camera stays on the driver's values; - a write-only relative control ("Pan, Relative", "Focus, Relative"...) moves the camera each time it is written; its last value stays in the settings and the PR writes it again on every load and settings update;
- uvcvideo lists "Focus (absolute)" before "Focus, Automatic Continuous", and cameras refuse a manual focus while autofocus is on, so a saved manual focus is never applied;
- it opens a second descriptor without
O_CLOEXEC(bug: linux-v4l2: a camera stays busy while recording because the muxer inherits its fd (upstream #12508) #339) on every update, where the capture's descriptor is already open.
The second half of obsproject/obs-studio#3092 (opening the properties writes the driver's defaults over values set with v4l2-ctl) does not happen on current master: obs_properties_apply_settings() collects the modified callbacks before device_selected() builds the controls, so none of them runs. The test below keeps it that way.
Proposed fix and failing test
Fix: port obsproject/obs-studio#13279's v4l2_apply_controls() and call it in v4l2_init() on the capture's descriptor, so it runs on start, on a restart and on reconnect, and from v4l2_update() when the capture keeps running. Skip write-only controls, and retry inactive or refused controls once after the others. Controls without a user value are never written, so values set with other tools survive. The source keeps a copy of its settings for the reconnect, which runs on the udev thread.
RED test (cmocka, test_v4l2_controls). It runs the real v4l2-input.c and v4l2-controls.c against a fake libv4l2 and raises the plugin's own udev signals for the replug. It needs no camera, kernel module or display. Eight cases:
- saved controls (integer, menu) are on the camera after the source is created;
- they are on it again after a replug that resets the camera to its driver's values;
- a control changed by
obs_source_update()reaches the camera without restarting the capture; - a saved manual focus is applied after autofocus is turned off, with a driver that flags it inactive and with one that only refuses it;
- control: a camera that already has the saved values is not written to, and controls without a saved value are never written;
- a relative control is not replayed on load, update or replug;
- building the properties writes nothing, and changing Brightness writes Brightness only, leaving a zoom set outside OBS alone.
5 of 8 fail today; the last 3 guard the fix.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 12, 2026
Claiming: this issue.
test_v4l2_controls(5 of 8 failing, no display needed): the real V4L2 source against a fake UVC webcam and a fake udev monitor; saved controls must be written at create, after a replug and on a script update, including a manual focus after autofocus is turned off, and relative controls must never be replayed.PR today.
linux-v4l2: Apply saved camera controls when the device opens
rdoupe commentedon Oct 12, 2026
@vpzomtrrfrt you reported this in obsproject/obs-studio#11633, so a heads-up: it's fixed here in obs-rust by #364, merged today with a regression test.
Cause: the V4L2 source only wrote a camera control (zoom, focus, exposure, ...) at the moment you changed it in Properties. Nothing wrote the saved values when the source started, when the camera was replugged, or when a script or obs-websocket changed the settings, so the camera ran on the driver's values until you touched the control again. ifohancroft, thadeupenna, EduardoRFS, Staacks, janakelarsson, desmondw and Pablomx2 reported the same thing over the years, and GrantAbell's upstream PR obsproject/obs-studio#13279 had the core idea; this builds on it (GrantAbell is credited as co-author). Now the saved controls that differ from the camera's values are written whenever the device opens (start, restart, replug) and on every settings update. Relative controls such as Pan (relative) are never replayed, since they move the camera each time, and a saved manual focus is applied after autofocus is turned off. The test drives the real V4L2 source against a simulated UVC webcam: before, saved controls were never written; now they are, after a replug too.
Not covered: tested against a simulated webcam, not real cameras or HDMI capture cards. Only controls you changed and that differ from the device are written, and a control the device refuses is just logged.
Workaround on stock OBS: after starting OBS or replugging, open the source's Properties and nudge each control once.
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 comes up with its saved settings would really help.
linux-v4l2: Apply saved camera controls when the device opens (obs-ru…
alerque commentedon Oct 12, 2026
This has "bug"ged me too, but I'm concerned the fix here might be worse than the bug. I have V4L2 devices with external PTZ controlers. If OBS is going to write these values when it (re-)connects etc, it needs to account for the external inputs: perhaps by having settings for which values to ignore and which to override, etc. Given that when I reconnect a camera it is likely to be in a slightly different placement, the PTZ controls are almost always used externally to get the aim right. These shouldn't be clobbered because OBS was opened.
rdoupe commentedon Oct 12, 2026
Good point, and it's a real gap. To be precise about what #364 does today: it only writes controls that have a saved value in OBS, meaning ones you changed in this source's Properties at some point, and only when they differ from what the camera reports. Controls you never touched in OBS are never written, and relative pan/tilt is never replayed. But if pan, tilt or zoom were ever set from OBS's Properties on that source, OBS now puts them back on every start and reconnect, which overrides your external PTZ controller. That's not acceptable for your setup.
I'm adding a per-source checkbox, "Restore camera controls when the camera connects", next to the controls in the source's Properties. Unchecked, OBS goes back to the old behaviour: it writes a control only when you change it in Properties, never on start or reconnect. I'll link the PR here. For an existing source you'd untick it once, and it's saved with the source.
rdoupe commentedon Oct 12, 2026
The option is up for review in #386: "Restore camera controls when the camera connects", the first item in the source's Camera Controls group. It's on by default (the behaviour from #364); unticked, OBS writes a control only when you change it in Properties, never on start, reconnect or a settings update. Ticking or unticking it writes nothing to the camera.
linux-v4l2: Add an option to not restore camera controls on connect
linux-v4l2: Add an option to not restore camera controls on connect (#…
rdoupe commentedon Oct 12, 2026
#386 is merged: untick "Restore camera controls when the camera connects" in the source's Camera Controls and OBS leaves your PTZ controller's pan, tilt and zoom alone on start and reconnect.
linux-v4l2: Restore saved camera controls only on their camera
linux-v4l2: Restore saved camera controls only on their camera (#460)