Skip to content

VideoSource

Video source

General class of video capture objects providing functionality to grab images from various sources. It implements basic interfaces like setup, start, stop of the video capture, and grabbing of frames. Internally utilizes ImageBuffer as storages.

new VideoSource(): VideoSource

Constructor

VideoSource

EventEmitterT.constructor

protected optional aspectRatio: number

Aspect ratio


buffer: ImageBuffer

Context of original stream


captureTime: number = 0

Timestamp of the last captured frame


protected optional clipRect: ClipRect

Clipping rectangle


protected optional sizeMax: number

Maximum capture resolutions


protected optional transpose: boolean

Transpose frames

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

EventEmitterT.addListener


capture(): boolean

Grab the next video frame

VideoSource grabs the static image permanently stored in embedded ImageBuffer object.

boolean

True if next frame was available and grabbed


dispose(): void

Dispose video source object

void


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

EventEmitterT.emit


eventNames(): (string | symbol)[]

List of emitter’s events

(string | symbol)[]

List of emitter’s events

EventEmitterT.eventNames


getMaxListeners(): number

Maximum number of listeners per event

number

Maximum number of listeners per event

EventEmitterT.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

EventEmitterT.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

EventEmitterT.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

EventEmitterT.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

EventEmitterT.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

EventEmitterT.once


pause(): void

Pause video capture

void


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

EventEmitterT.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

EventEmitterT.prependOnceListener


ratio(): number

Aspect ratio of the video stream

number

Aspect ratio of the video stream


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

EventEmitterT.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

EventEmitterT.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

EventEmitterT.removeListener


reset(): void

Reset video capture

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

void


setMaxListeners(n): this

Sets maximum number of listeners per event

number

Maximum number of listeners

this

This EventEmitter

EventEmitterT.setMaxListeners


setup(params?): Promise<boolean>

Setup video source

Sets up capture, overridden for particular video source. Video source 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. Default implementation sets video resolution according to size in VideoParams or 1920x1080 as the fallback. It captures static image, canvas is filled by white color.

VideoSourceParams

Parameters of video capture

Promise<boolean>

Promise resolved to the status of setup when done


size(): Size

Resolution of the video stream

Size

Resolution of the video stream


start(): Promise<void>

Start video capture

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

Promise<void>

Promise resolved when capture is started


protected updateSize(size): void

Update callback on video resize

Size

New size of the video stream

void