v0.0.2
This release introduces major refactor that simplifies the way the API works. Unfortunately, these changes are not backward compatible with the previous version. Meaning, if you adopt this release, you will have to modify your existing code a bit.
The new device
package
This release introduces a new device
package to create and access device functionalities.
Creating a device with the device
package
The device
API creates a device without having to use the v4l2 directly.
import "github.com/vladimirvivien/go4vl/device"
func main() {
device, err := device.Open("/dev/video0")
...
}
function device.Open
supports variable length arguments that can be used to specify the configuration of the device as it is being created:
func main() {
device, err := device.Open("/dev/video0",
device.WithIOType(v4l2.IOTypeMMAP),
device.WithPixFormat(v4l2.PixFormat{PixelFormat: getFormatType(format), Width: uint32(width), Height: uint32(height)}),
device.WithFPS(uint32(frameRate)),
)
}
Starting a device
Once a device is created, it can be started with a context as shown below
func main() {
device, err := device.Open("/dev/video0")
ctx, stop := context.WithCancel(context.TODO())
if err := device.Start(ctx); err != nil {
log.Fatalf("failed to start stream: %s", err)
}
}
Streaming device output
After a device has started, it's stream can be accessed as shown
func main() {
device, err := device.Open("/dev/video0")
ctx, stop := context.WithCancel(context.TODO())
if err := device.Start(ctx); err != nil {
log.Fatalf("failed to start stream: %s", err)
}
for frame := range device.GetOutput() {
....
}
}
Other enhancements
This release introduces access to more device information via additional types.
- Ability to enumerate all attached v4l2 devices
- Enhanced device capability information (including capability description)
- Access to media info (including bus info, driver, card, model, etc)
- Driver version information
- Video input information (i.e. video input status)
- Enhanced pixel format description (including format sizes)
- Enhanced crop capability (with default crop bounds)
- Access to stream parameters (including both capture and output capabilities and capture modes)
See the device info example for detail.