Skip to content

VideoCapture

Video capture

VideoCapture object provides means to grab images from a source. It implements all required functionality including video device initialization, setup, start/stop of capture and frame grabbing. Internally VideoCapture utilizes ImageBuffer as storage.

new VideoCapture(): VideoCapture

Constructor

VideoCapture

VideoSource.constructor

protected optional aspectRatio: number

Aspect ratio

VideoSource.aspectRatio


buffer: ImageBuffer

Context of original stream

VideoSource.buffer


captureTime: number = 0

Timestamp of the last captured frame

VideoSource.captureTime


protected optional clipRect: ClipRect

Clipping rectangle

VideoSource.clipRect


protected optional sizeMax: number

Maximum capture resolutions

VideoSource.sizeMax


protected optional transpose: boolean

Transpose frames

VideoSource.transpose


protected videoRef: HTMLVideoElement

Video element

addListener<E>(event, listener): this

Adds the listener function to the end of the listeners array

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

This EventEmitter

VideoSource.addListener


capture(): boolean

Grab the next video frame

VideoCapture grabs the next image from a video source (camera) and stores it in embedded ImageBuffer.

boolean

True if next frame was available and grabbed

VideoSource.capture


dispose(): void

Dispose video capture object

void

VideoSource.dispose


emit<E>(event, …args): boolean

Synchronously calls each of the listeners registered for the event

E extends "resize"

E

The name of the event

Args<CaptureEvents[E]>

Arguments passed to the listeners

boolean

True if the event had listeners, False otherwise

VideoSource.emit


eventNames(): (string | symbol)[]

List of emitter’s events

(string | symbol)[]

List of emitter’s events

VideoSource.eventNames


getMaxListeners(): number

Maximum number of listeners per event

number

Maximum number of listeners per event

VideoSource.getMaxListeners


listenerCount<E>(event): number

The number of listeners listening to the event

E extends "resize"

E

The name of the event

number

Number of listeners

VideoSource.listenerCount


listeners<E>(event): Function[]

Copy of the array of listeners for the event

E extends "resize"

E

The name of the event

Function[]

Copy of the listeners array

VideoSource.listeners


off<E>(event, listener): this

Removes the listener from the listener array for the event

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

This EventEmitter

VideoSource.off


on<E>(event, listener): this

Adds the listener function to the event

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

This EventEmitter

VideoSource.on


once<E>(event, listener): this

Adds a one-time listener function for the event

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

This EventEmitter

VideoSource.once


pause(): void

Pause video capture

void

VideoSource.pause


prependListener<E>(event, listener): this

Adds the listener function to the beginning of the listeners array

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

This EventEmitter

VideoSource.prependListener


prependOnceListener<E>(event, listener): this

Adds a one-time listener function to the beginning of the listeners array

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

VideoSource.prependOnceListener


ratio(): number

Aspect ratio of the video stream

number

Aspect ratio of the video stream

VideoSource.ratio


rawListeners<E>(event): Function[]

Copy of the array of listeners for the event including wrappers

E extends "resize"

E

The name of the event

Function[]

Copy of the listeners array

VideoSource.rawListeners


removeAllListeners<E>(event?): this

Removes all listeners, or those of the specified event

E extends "resize"

E

The name of the event

this

This EventEmitter

VideoSource.removeAllListeners


removeListener<E>(event, listener): this

Removes the specified listener from the listener array

E extends "resize"

E

The name of the event

CaptureEvents[E]

The callback function

this

This EventEmitter

VideoSource.removeListener


reset(): void

Reset video capture

After reset() capture may be started again only after setup().

void

VideoSource.reset


setMaxListeners(n): this

Sets maximum number of listeners per event

number

Maximum number of listeners

this

This EventEmitter

VideoSource.setMaxListeners


setup(params?): Promise<boolean>

Setup video capture

Sets up video device, streams and contexts with canvases. Video capture can be setup by simplified VideoParams opening default front/rear camera with provided resolution. Additional fine-grained MediaStreamConstraints can be passed via opts field providing the most flexible way to setup video stream (for example, by requesting specific deviceId). Stream constraints have higher priority than rest or params. Another options are an external MediaStream allowing custom video sources (e.g. remote stream) or a media file defined by url or FileParams that allows to limit maximum capture size in cases resolution is too big for a device.

VideoSourceParams

Parameters of video capture

Promise<boolean>

Promise resolved to the status of setup when finished

VideoSource.setup


size(): Size

Resolution of the video stream

Size

Resolution of the video stream

VideoSource.size


start(): Promise<void>

Start video capture

Video capture can be started only after successful setup().

Promise<void>

Promise resolved when capture is started

VideoSource.start


protected updateSize(size): void

Update callback on video resize

Size

New size of the video stream

void

VideoSource.updateSize