/node-uvc-control

Control UVC compliant USB webcams from node

Primary LanguageJavaScript

uvc-control

Control a USB Video Class compliant webcam from node. Most modern USB webcams use a common set of controls standardized by the USB Implementers Forum. You can use this set of controls to change certain things on the camera, such as the brightness, contrast, zoom level, focus and so on.

See also uvcc, which wraps uvc-control in a command line tool.

Example

const UVCControl = require('uvc-control')

// get the first camera by default
const camera = new UVCControl()
// or get a specific camera
const camera = new UVCControl({vid: 0x046d, pid: 0x082d})

camera.get('autoFocus').then(value) => console.log('AutoFocus setting:', value))
camera.set('brightness', 100).then(() => console.log('Brightness set!'))

For an interactive demo, run npm run serve and open http://localhost:3000.

Finding Your vendorId / productId

Use test/discover.js to find the right paramters.

$ node test/discover.js
[ { name: 'Logitech BRIO',
    vendorId: 1133,
    productId: 2142,
    deviceAddress: 7 },
  { name: 'Microsoft® LifeCam Studio(TM)',
    vendorId: 1118,
    productId: 1906,
    deviceAddress: 22 } ]

Installation

Libusb is included as a submodule.

On Linux, you'll need libudev to build libusb. On Ubuntu/Debian: sudo apt-get install build-essential libudev-dev

On Windows, use Zadig to install the WinUSB driver.

Then, just run npm install uvc-control

API

const UVCControl = require('uvc-control')

new UVCControl(options)

  • options - object containing options
  • options.vid - vendor id of your device
  • options.pid - product id of your device
  • options.deviceAddress - device address
const camera = new UVCControl(options)

List controls

Log the names of controls. You can get all controls, or a list of controls supported by the device.

UVCControl.controls.forEach(name => console.log(name))
console.log(cam.supportedControls)

camera.get( control_name )

Get the current value of the specified control by name.

camera.get('sharpness').then(value => console.log('sharpness', value))

camera.range( control_name )

Get the min and max value of the specified control by name. Some controls do not support this method.

camera.range('absolute_focus').then(range => {
  console.log(range) // { min: 0, max: 250 }
})

camera.set( control_name, value )

Set the value of the specified control by name.

camera.set('saturation', 100).then(() => console.log('saturation set!'))

camera.set( control_name, ...values )

Some controls have multiple fields. You can pass multiple values that align with the field offsets.

const pan = 34
const tilt = 27
camera.set('absolute_pan_tilt', pan, tilt).then(() => {
  console.log('absolute_pan_tilt set!')
})

camera.close()

Done? Good. Put away your toys and release the USB device.

camera.close()

Notes

You can find the full list of specs at the USB Implmentors Forum. Look for a document called USB Device Class Definition for Video Devices Revision 1.1 at their site here: http://www.usb.org/developers/docs/devclass_docs/ pdf mirror

To debug the USB descriptors, open chrome://usb-internals in Chrome

On Raspberry Pi, you need to run node as root in order to access USB devices. If you don't have access, you'll get a LIBUSB_ERROR_IO error on initialization. Alternatively, you can add a udev rule to grant access to the default user, as described in this AskUbuntu answer.

Pull requests and testers welcome!

Credits

Written by Pawel Szymczykowski and based on some Objective C examples by Dominic Szablewski found at http://phoboslab.org/log/2009/07/uvc-camera-control-for-mac-os-x. Maintained by Josh Beckwith.