https://github.com/taigrr/vidnumerator
Small library for checking if a path is a valid video camera
https://github.com/taigrr/vidnumerator
golang linux-video v4l2
Last synced: 2 months ago
JSON representation
Small library for checking if a path is a valid video camera
- Host: GitHub
- URL: https://github.com/taigrr/vidnumerator
- Owner: taigrr
- License: 0bsd
- Created: 2023-06-27T23:09:35.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2026-03-29T06:03:14.000Z (3 months ago)
- Last Synced: 2026-03-29T08:54:11.719Z (3 months ago)
- Topics: golang, linux-video, v4l2
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 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:
1. Scanning `/dev` for files matching the pattern `video*`
2. Using the `VIDIOC_QUERYCAP` ioctl to check if each device is a video capture device
3. 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
```go
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