A Dart package for controlling UVC compliant webcams.
You can find more information about UVC USB devices here on Wikipedia.
| Android | iOS | MacOS | Web | Linux | Windows |
|---|---|---|---|---|---|
| ❌ | ❌ | ✅ | ❌ | ❌ | ✅ |
import 'package:uvc/uvc.dart';
void main() {
final uvc = UvcLib(); // Load the libusb library
final camera = UVCControl(vendorId: 0x1532, productId: 0x0E05);
final value = camera.zoom.min;
camera.zoom.current = value == null ? 225 : value + 1;
camera.close();
uvc.dispose();
}
First, add uvc as a dependency in your pubspec.yaml file. Then run dart pub get or flutter pub get.
Next, you need to instantiate the UvcLib class which will open and setup the libusb
library for use in the app.
final uvc = UvcLib();
To open a camera and start controlling it, you must use UVCControl. Include the
vendor ID and product ID of the camera to control.
final camera = UVCControl(vendorId: 0x1532, productId: 0x0E05);
To find a list of cameras with their IDs, you can use:
final uvcDevices = uvc.getDevices(onlyUvcDevices: true);
final device = uvcDevices.first;
final vendorId = device.deviceDescriptor.vendorId;
final productId = device.deviceDescriptor.productId;
To get the zoom current value:
final value = camera.zoom.current;
To set the zoom current value:
camera.zoom.current = 225;
Close the camera when you are done.
camera.close();
It is always a good idea to unload the library when you are done using it.
uvc.dispose();
To get the range of valid values for zoom:
final min = camera.zoom.min;
final max = camera.zoom.max;
To use the pan or tilt values, just use the same code as zoom, but substitute the name pan and tilt for zoom:
camera.pan.current;
camera.pan.min;
camera.tilt.current;
camera.tilt.min;
camera.pan.current;
camera.tilt.current;
final camera = UVCControl(vendorId: 0x1532, productId: 0x0E05);
camera.zoom.current;
camera.zoom.defaultValue;
camera.zoom.max;
camera.zoom.min;
camera.zoom.resolution;
camera.backlightCompensation.current;
camera.brightness.current;
camera.contrast.current;
camera.contrast.saturation;
camera.contrast.sharpness;
camera.contrast.whitebalance;
camera.zoom.current;
camera.focusAuto.current;
camera.powerlineFrequency.current;
You can enable logging in UvcLib for troubleshooting. Just pass true to debugLogging when creating UvcLib.
final uvc = UvcLib(debugLogging: true);
You can also enable libusb logging in UvcLib for troubleshooting. Just pass true to debugLoggingLibUsb when creating UvcLib.
final uvc = UvcLib(debugLoggingLibUsb: true);
This uvc package utilizes the libusb library
via Dart FFI and it is
included as a dependency with the libusb Dart package.
All comments and pull requests are welcome.
Please sponsor or donate to the creator of uvc on Patreon.