https://github.com/kevmo314/go-uvc
Go library for accessing USB Video Camera (UVC) devices
https://github.com/kevmo314/go-uvc
camera usb uvc
Last synced: 2 months ago
JSON representation
Go library for accessing USB Video Camera (UVC) devices
- Host: GitHub
- URL: https://github.com/kevmo314/go-uvc
- Owner: kevmo314
- License: apache-2.0
- Created: 2024-05-10T14:26:57.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-23T01:36:40.000Z (12 months ago)
- Last Synced: 2024-05-23T03:38:34.493Z (12 months ago)
- Topics: camera, usb, uvc
- Language: Go
- Homepage:
- Size: 94.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# github.com/kevmo314/go-uvc
An almost-pure-Go library for accessing UVC devices. The library currently depends on libusb via cgo
but _not_ libuvc. One day this may change but libusb is much more complex.The non-Go equivalent of this library is [libuvc](https://github.com/libuvc/libuvc).

## Features
- [x] UVC 1.5 support
- [x] Input terminals (recording from cameras)
- [ ] Output terminals (displaying images on a device)
- [x] Isochronous and bulk transfer support
- [x] Android support
- [x] Video decoding API
- [ ] Camera controls
- [ ] UAC Audio support## Demo
`go-uvc` includes a debugging tool (the screenshot above) to connect to and debug cameras. To use it,
```sh
go run github.com/kevmo314/go-uvc/cmd/inspect -path /dev/bus/usb/001/002
```## Usage
A minimal example of how you might use `go-uvc`.
```go
package mainimport (
"image/jpeg"
"fmt"
"log"
"syscall""github.com/kevmo314/go-uvc"
"github.com/kevmo314/go-uvc/pkg/descriptors"
)func main() {
fd, err := syscall.Open("/dev/bus/usb/001/002", syscall.O_RDWR, 0)
if err != nil {
panic(err)
}ctx, err := uvc.NewUVCDevice(uintptr(fd))
if err != nil {
panic(err)
}info, err := ctx.DeviceInfo()
if err != nil {
panic(err)
}for _, iface := range info.StreamingInterfaces {
for i, desc := range iface.Descriptors {
fd, ok := desc.(*descriptors.MJPEGFormatDescriptor)
if !ok {
continue
}
frd := iface.Descriptors[i+1].(*descriptors.MJPEGFrameDescriptor)resp, err := iface.ClaimFrameReader(fd.Index(), frd.Index())
if err != nil {
panic(err)
}for i := 0; ; i++ {
fr, err := resp.ReadFrame()
if err != nil {
panic(err)
}
img, err := jpeg.Decode(fr)
if err != nil {
continue
}
// do something with img
}
}
}
}
```