Skip to content

linux-v4l2: Save device by id or path - #6493

Closed
ggodlewski wants to merge 2 commits into
obsproject:masterfrom
ggodlewski:v4l2-dev-by-id-or-path
Closed

ggodlewski wants to merge 2 commits into
obsproject:masterfrom
ggodlewski:v4l2-dev-by-id-or-path

Conversation

@ggodlewski

@ggodlewski ggodlewski commented May 16, 2022 •

Copy link
Copy Markdown
Contributor

Description

Use /dev/v4l/by-id or /dev/v4l/by-path when available in order to persist device binding to specific source.
Fixes #3003
Closes #3437

Motivation and Context

Currently v4l2 uses /dev/videoX which is not consistent across reboots and device reconnections.

This patch uses directories:

  • /dev/v4l/by-id - User has 2 devices: C920 and microscope. Sometimes I use them with another computer. I want to keep them assigned to specific sources/scenes without remembering which USB port to use.
  • /dev/v4l/by-path - User has 2 devices: front camera connected to first usb and top camera connected to second usb. If one of the devices is upgraded/changed it remains assigned to the same path.
  • /dev/videoX - Devices which are not present in above directories (eg. loopback)

The device can exists twice on the list (by-id vs by-path addressing). It's up to user which connect to the source.

In case of by-path device the source name consist of "bus_info (device name)"
Otherwise it uses current naming: "device name (bus_info)"

Fixes #3003
Closes #3437

How Has This Been Tested?

Tested with 5 different v4l2 devices:

ID 04fc:6353 Sunplus Technology Co., Ltd General USB Device (Lamax Electra)
ID 0c45:6366 Microdia Webcam Vitade AF (Digital microscope)
ID 534d:2109 MacroSilicon USB3.0 HD VIDEO (Video grabber)
ID 046d:082d Logitech, Inc. HD Pro Webcam C920
ID 046d:085e Logitech, Inc. BRIO Ultra HD Webcam

Test Case 1:

  • Plug all the devices, assign them by id, put them on the scene
  • It should display all the feeds

Test Case 2:

  • Having all devices assigned by id switch their USB ports.
  • The scene shouldn't change, all feeds in their old places.

Test Case 3:

  • Having all devices assigned by id turn off OBS
  • Run OBS
  • Nothing is on the scene
  • Plug devices in another order
  • Devices should be assigned to correct places by udev

Test Case 4:

  • Plug 2 devices, assign them by path, put them on the scene
  • Switch USB ports
  • The scene should have switched cameras

Test Case 5:

  • Create v4l2loopback: sudo modprobe v4l2loopback devices=1 video_nr=88 ; ffmpeg -re -f lavfi -i "movie=something.mp4" -f v4l2 /dev/video88
  • The v4l2loopback should be available on the list and working

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

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.

@RytoEX
RytoEX requested a review from kkartaltepe May 16, 2022 16:49
@RytoEX RytoEX added the kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. label May 16, 2022
@RytoEX RytoEX linked an issue May 16, 2022 that may be closed by this pull request
@RytoEX

RytoEX commented May 16, 2022

Copy link
Copy Markdown
Member

If this fixes/closes issues or other PRs, use "Fixes" or "Closes" before the Issue/PR reference to automatically link them together.

Does this resolve the lingering concern raised in #3437?

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.

@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch from 5c9491c to 3cdb2f8 Compare May 16, 2022 16:53
@RytoEX

RytoEX commented May 16, 2022

Copy link
Copy Markdown
Member

@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch from 3cdb2f8 to 57cc18a Compare May 16, 2022 17:54
@tytan652

Copy link
Copy Markdown
Collaborator

Does this resolve the lingering concern raised in #3437?

From PR description:

  • /dev/videoX - Devices which are not present in above directories (eg. loopback)

Tested with two cameras and v4l2loopback devices.

Seems like a yes.

@WizardCM WizardCM added the Seeking Testers Build artifacts on CI label May 21, 2022
Comment thread plugins/linux-v4l2/v4l2-input.c Resolved
Comment thread plugins/linux-v4l2/v4l2-input.c Resolved
Comment thread plugins/linux-v4l2/v4l2-input.c Resolved
Comment thread plugins/linux-v4l2/v4l2-input.c Resolved
@kkartaltepe

Copy link
Copy Markdown
Collaborator

Im not a big fan of having both id and path options since I don't think there is really a good way to expose this to the user. I dont think that anyone will get the intention behind the two names in the list without reading this PR. I was leaning towards saving by path but checking with windows it looks like we save by ID there so id prefer we just keep it consistent with windows and only expose by-id to users.

I like the code structure though, seems like a good solution to the issue of virtual devices.

@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch from 57cc18a to ad16694 Compare May 28, 2022 10:27
@ggodlewski

Copy link
Copy Markdown
Contributor Author

As a user I'm unable to remember which USB port I used previously for specific camera.
Linux exposes 2 ways to address v4l2 device to give users some flexibility. I think it's a good idea to expose this choice to OBS users as well.
I added prefix: 'Bus/Device' to unique_device_name.

@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch from ad16694 to ea596df Compare May 28, 2022 10:36
@tytan652

Copy link
Copy Markdown
Collaborator

Between /dev/v4l/by-id and /dev/v4l/by-path, is there one that manage correctly the scenario where the user connect two device from same model without getting them swapped between reboot.

/dev/v4l/by-path seems to be the only one that could avoid this.

Linux exposes 2 ways to address v4l2 device to give users some flexibility. I think it's a good idea to expose this choice to OBS users as well.

When you want to give choice, you need to check if any user that knows nothing about how device works on Linux could understand the choice they had to/can make.

Here you put everything in a list without even telling the difference between them.

@kkartaltepe
kkartaltepe force-pushed the v4l2-dev-by-id-or-path branch from ea596df to 59c8664 Compare May 29, 2022 00:48
@kkartaltepe

Copy link
Copy Markdown
Collaborator

I pushed some changes to clean up the freebsd defs. I think the code is fine now but I still dont believe the UX is really usable and we must choose one or the other of id or path. Or find a better UX.

@tytan652

tytan652 commented May 29, 2022 •

Copy link
Copy Markdown
Collaborator

Maybe with #5160 we could add information with another property list which makes the user choose between /dev/v4l/by-path (as default) and /dev/v4l/by-id. And also a third option for /dev/videoX .

  • Connection path (/dev/v4l/by-path)
  • Device ID (/dev/v4l/by-id)
    • Warning: If you use same model devices, they could get swapped between reboots
  • "My device does not show" (/dev/videox)
    • Warning: This way of selecting devices may not be consistent between reboots

@ggodlewski

Copy link
Copy Markdown
Contributor Author

Another property list is more clicking. Most users have just one camera.
#5160 is still open. #3437 was created almost 2 years ago. I don't think we should make this PR dependent on it.

Another, simple proposition:
Lets add disabled item between groups saying: "Advanced. Select device by connection:"

Screenshot at 2022-05-29 13-04-56

Normal user won't bother to click this list.
User with 2 cameras will select by id and ignore rest of the list.
User with cameras of the same model will use the "advanced-by-path" list.

@koo5

koo5 commented Jun 3, 2022

Copy link
Copy Markdown

Thanks, this patch is a lifesaver.

I would suggest that attempts to make this user-friendly by dumbing things down and hiding them and coming up with subjective labellings like "Advanced:..." and "Connection path" ... actually complicates it for 95% of users. And it's not a "Danger" if your cameras show up the other way around. No credentials are gonna get leaked. You just notice it in the process of tweaking your scenes. And this is linux. We have all devices in a filesystem tree, we are proud of it, and we are not afraid to use it. I'd prefer the dropdown to look basically like what you get when you run:
ls /dev/video* /dev/v4l/by-id/ /dev/v4l/by-path/,
just with the "friendly" names appended to each item (even these friendly names are only friendly as long as you only have one device of the same "friendly" name, beyond that, they are an attack on your sanity.

/dev/v4l/by-id:
    usb-MACROSILICON_USB_Video-video-index0@  (Bla bla)
    usb-MACROSILICON_USB_Video-video-index1@  (Bla bla)
/dev/v4l/by-path:
    pci-0000:06:00.1-usb-0:2:1.0-video-index0@ (Bla bla)
    pci-0000:06:00.1-usb-0:3:1.0-video-index1@ (Bla bla)
/dev/video* (Warning: This way of selecting devices may not be consistent between reboots):
    /dev/video0 (Bla bla)
    /dev/video1 (Bla bla)

@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch 4 times, most recently from c218b73 to 7a6bbe9 Compare June 23, 2022 18:40
@tt2468 tt2468 added the area/ui-ux Anything to do with changes or additions to UI/UX elements. label Jun 23, 2022
@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch from 7a6bbe9 to e1f934a Compare June 23, 2022 19:10
@ggodlewski

Copy link
Copy Markdown
Contributor Author

I've done more testing and resolved one bug. There was a problem because UDEV is always using real path to device instead of by-* scheme.
Now you're able to reconnect camera to different USB port during streaming or even start without any cameras and plug them during work.
I'd appreciate some testing.

@ggodlewski
ggodlewski force-pushed the v4l2-dev-by-id-or-path branch 2 times, most recently from 9f71de0 to 5416596 Compare June 26, 2022 09:06
@tytan652

tytan652 commented Jul 6, 2022

Copy link
Copy Markdown
Collaborator

Now that #5160 is merged, I reiterate my proposal:

We could add information with another property list which makes the user choose between /dev/v4l/by-path (as default) and /dev/v4l/by-id. And also a third option for /dev/videoX .

  • Per connection (e.g. USB port), /dev/v4l/by-path
  • Per device model, /dev/v4l/by-id
    • With a warning: If you use same model devices, they could get swapped between reboots
  • "My device does not show", /dev/videox
    • With a warning: This way of selecting devices may not be consistent between reboots

Why /dev/v4l/by-path is the default ? Because between /dev/v4l/by-id and /dev/v4l/by-path, the latter is the one that manage correctly the scenario where the user connect two devices from same model without getting them swapped between reboot considering that the user rarely move his set up (so rarely change connection port).

Another property list is more clicking. Most users have just one camera.

Adding potential clicks doesn't mean bad UX because it can be avoided with a good default (here with /dev/v4l/by-path) with descriptions or tool-tips if necessary.

@ggodlewski

Copy link
Copy Markdown
Contributor Author

@DarkDefender I will not provide any updates to this project. I wasted many hours to prepare my patches and I bought 2 more devices to do a proper testing. Maintainers ignored me so someone else has to work on that. Obviously linux support is not a priority.

@DarkDefender

Copy link
Copy Markdown

I don't know if you had some additional communication with the developers, but I wouldn't attribute any of this to malice or unwillingness to make linux support better.

As I am a Blender developer myself, I do see the same thing on our side of things regarding code contributions. We get a lot of pull requests but we don't really have time to properly spent the time needed on all of them. Usually that means that contributors has to jump through hoops to get things merged. It is not a good situation, but I there is simply not enough developers around to properly take care of every contributor.

I kinda see the same thing here.
@RytoEX do you have any time to get back to reviewing this?
If not, is there anyone else we can collaborate with?

@RytoEX

RytoEX commented Mar 11, 2023

Copy link
Copy Markdown
Member

@RytoEX do you have any time to get back to reviewing this?
If not, is there anyone else we can collaborate with?

I am not a Linux-based dev. My previous reviews here were only cosmetic. The only Linux-based contributor that I can think of who I would ask to review this is @kkartaltepe , who volunteers their free time as available. I can't force them to have more free time or force them to look at this.

@DarkDefender

DarkDefender commented Mar 11, 2023 •

Copy link
Copy Markdown

@RytoEX would you be fine if I step in as a reviewer and test this so I can vouch for the changes?
We do have a lot of webcams and capture cards at the Blender Studio, so I can quite easily create a very complex setup to stress test it.

I'm sure kkartaltepe didn't intentionally abandon this patch as he had a patch of his own addressing the same issue. (But his patch was seemingly abandoned in favor of this one). I think it is just that he legitimately doesn't or didn't have time.

So if I am allowed to step up and help this get merged, I will happily do so.
Especially because I'm going to include this patch in the Blender Studio OBS setup either way. However, I would like others to be able to use multiple v4l sources without ordering issues on reboot.

@kkartaltepe

Copy link
Copy Markdown
Collaborator

I did look at it again and it again seemed fine from a code perspective. But as I said " I think the code is fine now but I still dont believe the UX is really usable and we must choose one or the other of id or path. Or find a better UX." and as the author said "@tytan652 it this case someone needs to fork this PR and prepare working proposition. I already spent more time than expected."

This is reasonable code and probably will help whoever wants to do that fork and prepare something with better ux, but for me im not really convinced we should merge this as is and then try to change the UI again later. In fact merging this will probably just prevent us from ever making it more user friendly as such changes would probably break users who depend on having all these options available.

Its definitely at least partially my fault if I wasnt clear the main problem here is not the code but the UX, and at least my position is it should just work like windows.

@DarkDefender

DarkDefender commented Mar 11, 2023 •

Copy link
Copy Markdown

Thanks for clarifying your position

Main problem here is not the code but the UX, and at least my position is it should just work like windows.

But the issue here is that under the hood this doesn't work like on Windows. So to me, trying to force the interface to be like Windows would be a mistake.

To me, it seems like these two options that tytan652 mentioned are very useful and should be exposed:

  • Per connection (e.g. USB port), /dev/v4l/by-path
  • Per device model, /dev/v4l/by-id

This is because in my experience having "Per connection" would be a life saver when running bigger events like the Blender Conference. There we had cameras or capture cards break during the event and being able to simply delegate certain usb ports to a specific video input would make swapping out equipment really easy.
So instead of requiring people to change source settings, they could simply just plug in the replacement device in the same port and it will work without any further intervention.

For most users though, I think they will most likely just use the "Per device" mode.
(IE, they can plug the device in where ever they want and it will be mapped to the same source no matter what)

To me simply having the option in the UX to select which method you want to use shouldn't be too confusing or hard to understand. So I don't see why we would need to restrict ourselves to one or the other.

That is how I envision it at least. Do you agree that it sounds reasonable?
If not, perhaps we can discuss it some more to see if we can come to an agreement?

but for me im not really convinced we should merge this as is and then try to change the UI again later

100% agree. The design of how we want things to work should be agreed upon and implemented before merging.
Otherwise it could just lead to things not getting done later.

@ggodlewski

Copy link
Copy Markdown
Contributor Author

We do have a lot of webcams and capture cards at the Blender Studio

@DarkDefender do you have any of Logitech BRIO or Kiyo Pro cameras? There is also #7346 PR which gives more controls like FOV and HDR. I wasn't able to find anyone to test it.

As I am a Blender developer myself, I do see the same thing on our side of things regarding code contributions.

Oh, what a coincidence. I wanted to provide something for Blender and now I'm afraid ;).

@DarkDefender

DarkDefender commented Mar 12, 2023 •

Copy link
Copy Markdown

I'm unsure if we have a Brio model, I have to check. But I do know that we have a Logitech MeetUp camera. It seems like it at least might be able to use the tilt and pan controls. So I could try that out if you want to :)

Oh, what a coincidence. I wanted to provide something for Blender and now I'm afraid ;).

I think it is much less frustrating if you know what to expect before hand.
Before writing any code, I can recommend that you try to contact the developer in charge of the area you want to work in and talk through what you want to contribute.
This usually makes the process a lot smoother as then you can come to an agreement about:

  1. Will you contribution be something that would be accepted in the first place
  2. If so, how will it be implemented
  3. Get a picture of when the developer in question has time to review and merge your code.

BTW, with the updates posted in this pull request, do you want to continue or should I try to take over?
Of course I haven't heard back yet from kkartaltepe, but for me personally I just think we only need to polish the UI presentation a bit.

It should be nice and intuitive if we either do two buttons like the "Vertices/Edges" toggle buttons in the picture to change between "by-id" and "by-path":
screenshot
Then the user can hover over those buttons and we can have tool tips that explain them in detail.
Of course we could also just have it be a drop down menu for the "mode selection" instead (with tool tips there as well of course).

This is so it is very clear which "mode" the v4l source is in. What do you think?

@ggodlewski

Copy link
Copy Markdown
Contributor Author

I do know that we have a Logitech MeetUp camera. It seems like it at least might be able to use the tilt and pan controls. So I could try that out if you want to :) For me it's so useful to finally have proper FOV support under Linux.

That would be cool. You'll probably need to add GUID for this camera. I curious about the result.

BTW, with the updates posted in this pull request, do you want to continue or should I try to take over?

My job here is done. The last thing I can maybe do is to rebase #7346 after this is merged. Feel free to take it over.

The interface looks cool.

@DarkDefender

Copy link
Copy Markdown

@kkartaltepe do you think you will have any time to spend on discussing the UI design?
As it seems like you are OK with the code, perhaps I could get someone else involved if you don't have time.
Because the remainder of the potential changes do not really need any Linux specific knowledge or expertise.

@kkartaltepe

Copy link
Copy Markdown
Collaborator

@kkartaltepe do you think you will have any time to spend on discussing the UI design? As it seems like you are OK with the code, perhaps I could get someone else involved if you don't have time. Because the remainder of the potential changes do not really need any Linux specific knowledge or expertise.

the best place to have a design discussion is probably on the discord where most developers are. There may be other people more interested in supporting multiple card lookup strategies.

@DarkDefender

Copy link
Copy Markdown

That sounds like a great idea!
I didn't think about hopping onto discord to do this. But it makes total sense 😅

@keriszafir

keriszafir commented Mar 25, 2023 •

Copy link
Copy Markdown

Dealing with this issue, got an additional problem with camera disconnect/reconnect not being detected if I change the "device_id":"/dev/video2" etc. in the scene collection json file. This will break automatic reconnection and feed restart.

Test case and observations:

  1. Fresh OBS config, a scene with a single camera set in OBS, but two cameras present in the system: works okay and the video feed comes back after the camera is disconnected and reconnected. On OBS/system restart, the other camera feed may appear instead of the previously selected one.
  2. To mitigate this and keep cameras persistent, I made custom rules for my cameras, adding symlinks in /dev directory, e.g.
    KERNEL=="video[0-9]*", ATTR{name}=="Razer Kiyo Pro", ENV{ID_V4L_CAPABILITIES}==":capture:", SYMLINK+="video-kiyo"
    The ENV{ID_V4L_CAPABILITIES}==":capture:" match ensures that only the device file with video capture rather than metadata capabilities will be symlinked.
  3. Then I edited the ~/.config/obs-studio/basic/scenes/{scene_collection_name}.json while OBS was not running, changing the video capture device settings manually "device_id":"/dev/video2" to "device_id":"/dev/video-kiyo" or "device_id":"/dev/v4l/by-id/usb-Razer_Inc_Razer_Kiyo_Pro-video-index0". The new setting is persistent and no video input devices were swapped anymore, but it comes at a price. Both custom-edited device_id entries break the automatic (udev based) disconnection and reconnection detection. I started OBS from terminal observing the log. After pulling the camera's USB plug, the video feed freezes, but it doesn't restart after plugging it back in (which is the expected behavior and it was the case with "device_id":"/dev/video2"). I don't get info: v4l2-input: Device {path} disconnected and info: v4l2-input: Device {path} reonnected log entries respectively. In case of unstable USB connections like on my Kiyo Pro, this will lead to camera feed freezing and not restarting, forcing me to close and restart OBS.

Multiple cameras of the same model aren't handled gracefully by the udev persistence rule (in Debian bookworm/sid: /lib/udev/rules.d/60-persistent-v4l.rules):

ACTION=="remove", GOTO="persistent_v4l_end"
SUBSYSTEM!="video4linux", GOTO="persistent_v4l_end"
ENV{MAJOR}=="", GOTO="persistent_v4l_end"

IMPORT{program}="v4l_id $devnode"

SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"
KERNEL=="video*", ENV{ID_SERIAL}=="?*", SYMLINK+="v4l/by-id/$env{ID_BUS}-$env{ID_SERIAL}-video-index$attr{index}"

TEST!="index", GOTO="persistent_v4l_end"
ATTR{index}!="?*", GOTO="persistent_v4l_end"

IMPORT{builtin}="path_id"
ENV{ID_PATH}=="?*", KERNEL=="video*|vbi*", SYMLINK+="v4l/by-path/$env{ID_PATH}-video-index$attr{index}"
ENV{ID_PATH}=="?*", KERNEL=="audio*", SYMLINK+="v4l/by-path/$env{ID_PATH}-audio-index$attr{index}"

LABEL="persistent_v4l_end"

but this file could be overriden with a custom rule in /etc/udev/rules.d with more fine-grained rules e.g. adding serial number or other unique identifier from the device's attributes. There may be a way, it's just system-level settings rather than OBS.

@GeorgesStavracas

Copy link
Copy Markdown
Member

(Copying this response from #9246)

Thank you very much for the contribution and for the amount of effort put in this PR. I'm afraid I come with bad news though :(

After deliberating about this feature, the interaction flow is not what we want to go as the intended user experience. What we want going forward is basically how the macOS integration in OBS Studio handles cameras. Each device gets a unique identifier - even devices of the same model - and that's what's used to address the device. That means that whatever device the user selects in OBS Studio is picked, regardless of where it is connected.

Picking the device of a specific bus might incur losing data, or other sorts of incompatibilities, as if the user swaps the device and the new device doesn't support the same properties of the old one.

As it is right now, I don't think the behaviour above is what our v4l2 code does. I think it should be what it does. Contributions that implement this behaviour would be welcomed.

Hope the user experience considerations that led to rejecting this feature were cleared up. I appreciate that a lot of effort was put in this PR. It is unfortunate that it took so long to close this. I hope we (I) can do better and act faster in the future.

@amazingfate

Copy link
Copy Markdown

I have a rk3588 board with hdmirx port, but there is only /dev/v4l/by-path:

$ ls -l /dev/v4l/*/*
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdb50000.video-codec-video-index0 -> ../../video3
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdb50000.video-codec-video-index1 -> ../../video4
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdb80000.rga-video-index0 -> ../../video2
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdba0000.video-codec-video-index0 -> ../../video5
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdc38000.video-decoder-video-index0 -> ../../video0
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdc70000.video-codec-video-index0 -> ../../video6
lrwxrwxrwx 1 root root 12 10月 12 19:38 /dev/v4l/by-path/platform-fdee0000.hdmi_receiver-video-index0 -> ../../video1

Debian has added this pr to the obs-studio is packages: https://salsa.debian.org/multimedia-team/obs-studio/-/commit/4a353a071febf315746a9d184bc6506e31421882, and this pr code is also included in ubuntu 24.04.

When running obs-studio installed from debian or ubuntu's apt repo, if I add a v4l2 capture device, obs will crash. After rebuilding obs-studio without this patch, issue is gone.

@kkartaltepe

Copy link
Copy Markdown
Collaborator

There are no debian maintainers here. If you are trying to report a bug about debian you are in the wrong place.

@amazingfate

Copy link
Copy Markdown

I'm just posting a FYI message, not asking someone to fix the bug in debian.

@ggodlewski

Copy link
Copy Markdown
Contributor Author

@amazingfate thanks for the info. I didn't expect that to be included into Debian :).
It's hard to say what is wrong without the logs.
I tried changing the code to use not-existing path /dev/v4l/by-id2/ and it doesn't crash.

@ggodlewski

Copy link
Copy Markdown
Contributor Author

@keriszafir sorry for the late reply. I don't know if it's still relevant.
You can try commenting the following part from v4l2-input.c. The entries would be duplicated (video* and v4l/*) but it could work.

//if (device_already_added) {
//      goto next_entry;
//}

@DarkDefender

DarkDefender commented Oct 14, 2024 •

Copy link
Copy Markdown

@ggodlewski @amazingfate I created a updated version of this PR here: #9246

I'm working at the Blender Studio and we have been using that patch without issues since then.
We are hosting the patch ourselves here: https://projects.blender.org/ZedDB/studio_portage_conf/src/branch/master/patches/media-video/obs-studio/fix_v4l_device_order.patch

If you have any issues with the patch you could report it in the https://projects.blender.org/ZedDB/studio_portage_conf repo.

There is also a design task about it here in the OBS repo: obsproject/design#21
Hopefully we can get the ball rolling again as this solves a lot of issues with various camera setups.

@DarkDefender

DarkDefender commented Oct 14, 2024 •

Copy link
Copy Markdown

If you guys have any feedback on the design task please drop a message in that task.
I really want to know what people think about my proposed UI.

@ggodlewski

Copy link
Copy Markdown
Contributor Author

@DarkDefender I don't care much about UI as long as it supports all my use cases (id, path, other).

I also another PR which changes slightly UI. It might be less controversial since it only adds missing controls.
#7346 / ggodlewski#1
It depends on this PR.

@christephan1

Copy link
Copy Markdown

I also don't care UI. What I want is just to fix the current OBS bug.
Glad to hear that Ubuntu 24.04 includes this, my original plan is to integrate it by myself when we need to update version.
I don't know why obs team reject this. As the reason they mentioned is exactly why we need this. People still reporting issues in #3003 , they should not suffer that if this PR got merged.

@amazingfate

Copy link
Copy Markdown

@ggodlewski @amazingfate I created a updated version of this PR here: #9246

I'm working at the Blender Studio and we have been using that patch without issues since then. We are hosting the patch ourselves here: https://projects.blender.org/ZedDB/studio_portage_conf/src/branch/master/patches/media-video/obs-studio/fix_v4l_device_order.patch

If you have any issues with the patch you could report it in the https://projects.blender.org/ZedDB/studio_portage_conf repo.

There is also a design task about it here in the OBS repo: obsproject/design#21 Hopefully we can get the ball rolling again as this solves a lot of issues with various camera setups.

Your patch works fine. After clicking add video capture device, I get default By Device ID, but no device to choose, then I select By Bus Path, and I can see video from my hdmirx device.

@DarkDefender

DarkDefender commented Oct 14, 2024 •

Copy link
Copy Markdown

@amazingfate Awesome! Perhaps you could poke the Debian maintainers to switch to my patch? I'm not using Ubuntu/Debian myself, so I think it would be best for an actual end user to do it. (Especially since you had issues with the current included patch).

Also useful to know that you have a device that only has a "by path" and not "by id".

@amazingfate

Copy link
Copy Markdown

@amazingfate thanks for the info. I didn't expect that to be included into Debian :). It's hard to say what is wrong without the logs. I tried changing the code to use not-existing path /dev/v4l/by-id2/ and it doesn't crash.

Here is the log when using obs with your patch:

info: v4l2-input: Start capture from 
error: v4l2-input: Unable to open device
error: v4l2-input: Initialization failed, errno: No such file or directory
info: User added source 'Video Capture Device (V4L2)' (v4l2_input) to scene '场景'
free(): invalid pointer

It seems that no capture device is deteted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ui-ux Anything to do with changes or additions to UI/UX elements. kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. Seeking Testers Build artifacts on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webcam ordering is not persistent in Linux