Repository navigation
linux-v4l2: Save device by path - #3437
kkartaltepe wants to merge 1 commit into
Conversation
8f3b820 to
e0dd0ca
Compare
|
formatting was a bit weird, fixed up now. |
This adjusts device listing to be by /dev/v4l/by-path which is based on where the device is plugged in instead of when it is initialized. This should help people with multiple devices across restarts. Old plugin data will still work unchanged, when users modify settings the new options will be transparently backed by the new keys but names presented remain consistent.
e0dd0ca to
0f3bd8b
Compare
|
Thank you this will really help! I will test next time I have a long enough window to muck with my OBS install! |
|
@khng300 we should check this on FreeBSD |
|
This should leave freebsd unchanged other than trying to resolve links which should harmlessly fail. If BSDs present /dev/v4l/by-path/ and it works im happy to remove the fork for BSD systems. |
This path should be a product of systemd setup on linux right? |
|
I use this patch in my build of OBS Studio 26.0.2 and I have to say it is an essential addition for anyone using multiple capture devices. I used 4, 6 or 8 capture devices (misxture of PCIe and USB) and this patch prevents the random shuffling of camera sources 👍 |
|
Are earlier versions forward-compatible with this? |
|
This only changes how devices are enumerated in the settings, old source configurations/device initialization will continue to work unchanged. |
|
Any specific reason why this is not merged? This patch really saved my ass when we had a studio setup with a lot of v4l devices connected. On each reboot the 8 devices would be scrambled and it took considerable amount of time to set up everything again correctly. However by creating a custom build with this patch applied, no additional setup is required after the initial configuration of the v4l devices. |
|
Because we have hundreds of PRs, tens of thousands of lines of code to review, and only two full-time developers. This, while maybe important to your specific setup and an inconvenience, is not a high priority compared to other issues/bug fixes. We'll get to it when we can. |
|
Thanks for the respons. Now I know that it hasn't been forgotten :) |
|
This patch applies cleanly on OBS 27.0.0-rc3 and continues to work reliably. |
|
I was thinking about this patch again, but it seems like it v4l2loopback devices dont end up registered under the /dev/v4l/ tree. So there is probably more work to also include those video devices without paths. |
| const char *basedir = "/dev/"; | ||
| #else | ||
| dirp = opendir("/sys/class/video4linux"); | ||
| const char *basedir = "/dev/v4l/by-path/"; |
There was a problem hiding this comment.
Can you use by-id instead of by-path? This will allow plugging capture devices in different USB ports without the need to change the config (the ID will stay the same, but the path will change).
|
this issue is really a showstopper when frequently moving between office and home office - no one there who can accept the patch provided? |
The patch author set this to Draft on May 28, 2021 for the following reason:
We don't merge Draft PRs. Even if we did, the conditions previously explained also still apply. We'll get to this when we can. |
|
Closing this out as I doubt ill un-draft this. |
|
This merge will fix a problem that makes the OBS configuration break on every reboot for people with multiple V4L2 cameras. Random camera changes don't fail in a graceful way, some cameras don't support the same settings so when the devices randomly switch you never know what's going to happen on start, including crashes. I have to spend 30+ minutes every time I reboot fixing the camera settings and order. One can't just quickly fix the cameras by switching the device combo box either, each device has to deleted all of the devices and configured from scratch because they get bound to the incorrect source and you can't pick a video device that's already bound to another source. They can't be renamed because some settings and encoders don't apply to the switched devices and the configurations don't match up. Retaining stateful configuration settings on what has to be one of the primary sources used in OBS should be at the very top of the bug list in my opinion. Anyone who uses OBS on Linux with more than 1 V4L2 video device is affected by this. |
This comment was marked as spam.
This comment was marked as spam.
|
I have been suffering from this stupid problem which could have been fixed years ago for a long long time. So much so that I have written a small PHP script (sorry it's PHP, but I'm a bit strange like that...) which will edit the OBS configuration file for a set of scenes and replace any #!/usr/bin/php
<?php
$file = @$argv[1];
if (!$file) {
print "Usage: fixvid <json file>\n";
exit(10);
}
if (!file_exists($file)) {
printf("fixvid: Unable to open $file for reading\n");
exit(10);
}
$devices = array();
$dir = opendir("/dev/v4l/by-id");
while ($link = readdir($dir)) {
if (substr($link, 0, 1) == ".") continue;
$fullpath = "/dev/v4l/by-id/" . $link;
$l = $fullpath;
$target = readlink($l);
$target = str_replace("../../", "/dev/", $target);
$devices[$target] = "/dev/v4l/by-id/" . $link;
}
$json = json_decode(file_get_contents($file), false);
foreach ($json->sources as $num=>$source) {
if ($source->id == "v4l2_input") {
$dev = $source->settings->device_id;
if (array_key_exists($dev, $devices)) {
$json->sources[$num]->settings->device_id = $devices[$dev];
}
}
}
copy($file, $file . ".bak");
file_put_contents($file, json_encode($json, JSON_PRETTY_PRINT)); |

Description
This adjusts device listing to be by /dev/v4l/by-path which is based
on where the device is plugged in instead of when it is initialized.
This should help people with multiple devices across restarts.
Old plugin data will still work unchanged, when users modify settings
the new options will be transparently backed by the new keys but names
presented remain consistent.
Motivation and Context
/dev/videoX is not consistent across reboots. This fixes #3003 for users with multiple devices.
How Has This Been Tested?
Works with my devices. Seems it should also work with the freeBSD assuming they have readlink. Manually editing scene to have the previous config works fine.
Types of changes
Checklist: