Skip to content

Fixed duplicate Video Capture Device listing on Linux#344

Merged
Avasam merged 4 commits into
Toufool:mainfrom
poulpeit:_fix_linux_cameras
Apr 14, 2026
Merged

Fixed duplicate Video Capture Device listing on Linux#344
Avasam merged 4 commits into
Toufool:mainfrom
poulpeit:_fix_linux_cameras

Conversation

@poulpeit

Copy link
Copy Markdown
Contributor

This PR has been made in order to fix an issue on capture device listing in the settings menu on linux.

Video devices are listed in /sys/class/video4linux with "video<ID>".
When adding or removing a new webcam, a new folder video<ID> is created or deleted, but there is some edge cases where ID are not contiguous (example: plug two devices and remove the first one).

As the code is currently a range(0, <number of folder>), in these edge cases, capture devices are not properly detected.

To fix this, I changed get_input_devices to properly list every folders.
As a side effect, I had to set enumerate into get_input_devices instead of get_all_video_capture_devices

Please note that, as I don't have any Windows available, tests were made only on Linux, but these changes should not break Autosplit on Windows.

@Avasam

Avasam commented Mar 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks! I do have a duplicate cam listing issue on my Linux machine, so I can test this. Maybe not now though as I just came back from organising and running a gaming convention + show. Will need some time to recover.

@poulpeit

Copy link
Copy Markdown
Contributor Author

OK, I thought duplicate cam listing was an issue on my side, but obsiously no :)

I dug a bit and saw that this is a normal behavior. As explained on https://askubuntu.com/a/1191209 Linux kernel creates a second device for metadata and stuff.
Listing every video devices on /sys/class/video4linux will by design show the second device.

Instead of listing /sys/class/video4linux, I found that we should ask for capabilities for every device. This can be done by using ioctl, asking for VIDIOC_QUERYCAP data and check if the V4L2_CAP_VIDEO_CAPTURE flag is set.
A bit of explaination here: https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec/rn01re56.html

I changed the source code in order to check for this.
It seems to be a bit slower to get every video devices on the settings window, but nothing really annoying.

@Avasam

Avasam commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Tested with my Logitech C920 + some generic USB Video stick and both seemed fine ! Items deduplicated from list.

Instead of listing /sys/class/video4linux, I found that we should ask for capabilities for every device. This can be done by using ioctl, asking for VIDIOC_QUERYCAP data and check if the V4L2_CAP_VIDEO_CAPTURE flag is set. A bit of explaination here: linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec/rn01re56.html

I changed the source code in order to check for this. It seems to be a bit slower to get every video devices on the settings window, but nothing really annoying.

I don't mind it being slower, but I remember previously having a similar approach on Windows (request a frame from each iterated item) and it would cause the device to freeze if it was already in use !

See the comment under get_camera_info.

Luckily I still have my GV-USB2, which had that behaviour. So I'll go test with that.

Please note that, as I don't have any Windows available, tests were made only on Linux, but these changes should not break Autosplit on Windows.

Looking at the code change, I agree I don't see any reason this would affect Windows.

Comment thread src/capture_method/__init__.py Outdated
@Avasam Avasam changed the title fix camera listing Fixed duplicate Video Capture Device listing on Linux Apr 14, 2026
@Avasam

Avasam commented Apr 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks! I've pushed some (I think) improvements. Feel free to challenge them or open a new PR if you think I missed something !

@Avasam Avasam merged commit 723de4d into Toufool:main Apr 14, 2026
12 checks passed
@poulpeit

Copy link
Copy Markdown
Contributor Author

Thanks for the merge and glad it helped. I'll have a try on the new code, but it seems to be great!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants