You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should be able to start and stop V4L2 input while recording, e.g. when changing resolution of the camera.
Current Behavior
Freezes after the resolution is changed.
Steps to Reproduce
Add a "Video Capture Device (V4L2)" to the scene, select a webcam.
Activate Start recording.
Open properties of the "Video Capture Device (V4L2)" source, and make any change that requires camera restart (e.g. frame rate, resolution, etc).
The device freezes.
The device appears to be closed once Stop recording is activated and can then be re-activated.
When not recording, the device stops and starts without problem.
Anything else we should know?
This goes as far back as 30.2.3 at least; haven't tested further back as it gets more difficult to build. Maybe this is a dependency issue or perhaps something in certain kernels - it seems odd that the file (descriptor) isn't cleaned up properly by the call to v4l2_close().
Would like to confirm if others have experienced the same issue.
Currently running 6.14.0-27 generic on Ubuntu 24.04 (HWE kernel line).
Just tried strace -e trace=open,openat,close; and now it seems that it isn't encoder related. So that's a false flag. Also I can see that the close and open operations are succeeding.
I tried adding a pause in before attempting to re-open the camera while recording, but it still fails.
I think it's going to take someone smarter than me to figure this one out.
changed the title [-]V4L2 input does not close while recording with NVIDIA NVENC and FFMPEG VAAPI[/-][+]V4L2 input does not close while recording[/+]on Aug 15, 2025
Start recording in OBS studio with the webcam selected in the Video Capture Device (V4L2) source.
Open the properties (while recording), select the loopback (test feed) which is /dev/video10 and it starts ok.
Try to switch back to the webcam; it fails:
info: v4l2-input: /dev/video10: Stopped capture after 40 frames
info: v4l2-input: Start capture from /dev/video0
error: v4l2-input: Unable to set input 0
error: v4l2-input: Initialization failed, errno: Device or resource busy
If I switch back to the loopback; it starts no problem.
Again, can only restart the camera once I have stopped recording.
I used modprobe uvcvideo trace=0xFFFF and here it looks like the device isn't released (e.g. a trace of uvc_v4l2_release) until the recording is stopped - this is in spite of the fact that I'm certain that v4l2_close is being called (and returning 0) when the camera resolution is changed.
Activity
stephematician commentedon Aug 15, 2025
Forgot to mention; when using x264 encoder - the camera can be stopped and started no problem.
stephematician commentedon Aug 15, 2025
Just tried
strace -e trace=open,openat,close; and now it seems that it isn't encoder related. So that's a false flag. Also I can see that the close and open operations are succeeding.I tried adding a pause in before attempting to re-open the camera while recording, but it still fails.
I think it's going to take someone smarter than me to figure this one out.
[-]V4L2 input does not close while recording with NVIDIA NVENC and FFMPEG VAAPI[/-][+]V4L2 input does not close while recording[/+]stephematician commentedon Aug 16, 2025
Also occurs on
6.8.0-71-generic; so that means I've tried different OBS builds, different encoders, and different kernels.I'm still no closer to seeing where the bug comes from.
[EDIT]
I can start and stop a V4L2 loopback device without problem; i.e.:
video_nr=10 max_buffers=4and feed it with gstreamer video test source:/dev/video10and it starts ok.Again, can only restart the camera once I have stopped recording.
I used
modprobe uvcvideo trace=0xFFFFand here it looks like the device isn't released (e.g. a trace ofuvc_v4l2_release) until the recording is stopped - this is in spite of the fact that I'm certain thatv4l2_closeis being called (and returning 0) when the camera resolution is changed.[/EDIT]
stephematician commentedon Aug 16, 2025
Using GDB; I'm seeing that the device is finally released here:
stephematician commentedon Apr 6, 2026
@hoshinolina I noticed your recent PR #13198 addressed some unusual fd close behaviour, do you know if anything you found there could be related?
stephematician commentedon Oct 12, 2026
This is due to leaking fd's into a spawned process, which can happen via
obs-studio/libobs/util/pipe-posix.c
Line 97 in 7d98beb
The question is what is the correct fix (open the V4L2 device with O_CLOEXEC, or something else?)