mirror of
https://github.com/taigrr/vidnumerator.git
synced 2026-04-01 20:58:51 -07:00
cd/tests-quality-deps
- Add 6 tests covering nil receiver, invalid fd, invalid path, regular file, device enumeration, and capability constant - Fix typo: fileDesciptor -> fileDescriptor - Extract magic number 69206017 into V4L2CapVideoCapture constant - Bump golang.org/x/sys v0.41.0 -> v0.42.0 - Bump Go 1.26.0 -> 1.26.1 - Add staticcheck to CI workflow
VidNumerator
This is a tiny library that uses syscalls to efficiently determine which /dev/videoN devices
are webcams and which are the additional metadata control handles.
The list of strings returned are the full filepaths to valid devices.
Important
In order for this library to work properly, the executing user must have either root or video group privileges
Technical Details
The library works by:
- Scanning
/devfor files matching the patternvideo* - Using the
VIDIOC_QUERYCAPioctl to check if each device is a video capture device - Filtering out non-capture devices (like metadata control handles)
The core functionality is implemented through direct syscalls to the Linux kernel's V4L2 (Video4Linux2) API. The library uses the VIDIOC_QUERYCAP ioctl command to query device capabilities and determine if a device supports video capture.
Usage
devices, err := vidnumerator.EnumeratedVideoDevices()
if err != nil {
// handle error
}
// devices will contain paths like "/dev/video0", "/dev/video2", etc.
Implementation Notes
- Uses direct syscalls via
golang.org/x/sys/unix - Implements custom ioctl constants for V4L2 device querying
- Checks for specific device capabilities (0x4200001) to identify capture devices
Description
Languages
Go
100%