Skip to content

Modify the configuration of the usb camera, support windows and linux, support electron

Notifications You must be signed in to change notification settings

dusionlike/camera-settings

Repository files navigation

camera-settings npm

English | 中文

Retrieve and modify the configuration of USB cameras, supporting both Windows and Linux environments. Typically used for Electron applications.

Installation

npm install camera-settings

Usage

import { CameraSettings } from "camera-settings";

(async () => {
  const cs = new CameraSettings(0);
  await cs.open();

  // Get camera settings
  const settings = await cs.getSettings();

  // Modify camera settings, such as white balance
  await cs.setSettings([{ prop: "WhiteBalance", val: 2900, isAuto: true }]);

  // Get all available resolutions
  const resolutions = await cs.getResolutions();

  await cs.close();
})();

API

CameraSettings

constructor(cameraId: number | string)

  • cameraId Camera index, starting from 0, or the camera name, e.g., HD USB Camera

open(): Promise<void>

Performs initialization tasks, such as finding the device.

close(): Promise<void>

Clears cache and releases resources.

getSettings(): Promise<CameraSetting[]>

Retrieve camera settings.

interface CameraSettingInfo extends CameraSettingSetInfo {
  prop: TagCameraControlProperty | TagVideoProcAmpProperty;
  val: number;
  isAuto?: boolean;
  min: number;
  max: number;
  step: number;
  /** rangeFlags & 1 Auto; rangeFlags & 2 Auto Manual */
  rangeFlags: number;
  /** Default configuration */
  def: number;
  ctrlType: "video" | "camera";
}

setSettings(settings: CameraSetting[]): Promise<void>

Modify camera settings.

interface CameraSetting {
  prop: TagCameraControlProperty | TagVideoProcAmpProperty;
  val: number;
  isAuto?: boolean;
}

getResolutions(): Promise<Resolution[]>

Retrieve all available resolutions.

interface Resolution {
  width: number;
  height: number;
  /** mjpg, yuy2, yuyv... */
  type: string;
}

About

Modify the configuration of the usb camera, support windows and linux, support electron

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published