Skip to main content

@auvious/media-tools / BackgroundFilter

Class: BackgroundFilter

Generic for input

Implements​

Table of contents​

Constructors​

Properties​

Methods​

Constructors​

constructor​

• new BackgroundFilter(timers?): BackgroundFilter

Parameters​

NameType
timers?Timers

Returns​

BackgroundFilter

Properties​

anchor​

• Private anchor: number = 0


backgroundConfig​

• Private backgroundConfig: BackgroundConfig


bitmap​

• Private bitmap: null | ImageBitmap = null


canvas​

• Private canvas: CanvasElement


canvasStream​

• Private Optional canvasStream: null | MediaStream = null


counter​

• Private counter: number = 0


events​

• events: Events<IBackgroundFilterEventMap>


hasUnloaded​

• Private hasUnloaded: boolean = false


image​

• Private image: null | HTMLImageElement = null


modelFileName​

• Private modelFileName: string = fullModelFileName


name​

• name: string = "background-filter.video"

distinct effect name

Implementation of​

IMediaEffect.name


pipeline​

• Private pipeline: null | RenderingPipeline = null


postProcessingConfig​

• Private postProcessingConfig: PostProcessingConfig


rendering​

• Private rendering: boolean = false

control the render loop


segmentationConfig​

• Private segmentationConfig: SegmentationConfig


streamIn​

• Private Optional streamIn: MediaStream


streamOut​

• Private streamOut: null | MediaStream = null


targetTimePerFrame​

• Private targetTimePerFrame: number = 0


tflite​

• tflite: null | TFLite = null


timers​

• Private Optional timers: Timers


useWebGL​

• Private useWebGL: boolean = false


video​

• Private video: HTMLVideoElement

Methods​

frameEnd​

▸ frameEnd(): void

Returns​

void


genOutput​

▸ genOutput(): void

Returns​

void


getTime​

▸ getTime(): number

Returns​

number


load​

▸ load(options): Promise<boolean>

load and initialize models

Parameters​

NameTypeDescription
optionsObjectassetsPath: absolute url where wasm and models reside
options.assetsPathstring-
options.image?HTMLImageElementonfail triggers if fails to use image
options.lite?boolean-
options.useWebgl?boolean-
options.wasmSimd?booleanforce wasm SIMD on/off (defaults to auto-detect)

Returns​

Promise<boolean>

boolean


loadCanvasPipeline​

▸ loadCanvasPipeline(): void

Returns​

void


loadModel​

▸ loadModel(assetsPath): Promise<void>

Parameters​

NameType
assetsPathstring

Returns​

Promise<void>


loadPipeline​

▸ loadPipeline(): Promise<boolean>

Returns​

Promise<boolean>


loadWasm​

▸ loadWasm(assetsPath, wasmSimd?): Promise<boolean>

Parameters​

NameType
assetsPathstring
wasmSimd?boolean

Returns​

Promise<boolean>


loadWebGLPipeline​

▸ loadWebGLPipeline(): void

Returns​

void


onOutput​

▸ onOutput(callback): () => void

listen for output changes

Parameters​

NameType
callback(stream: MediaStream) => void

Returns​

fn

▸ (): void

Returns​

void

Implementation of​

IMediaEffect.onOutput


onUnload​

▸ onUnload(callback): () => void

listen for effect removal

Parameters​

NameType
callback() => void

Returns​

fn

▸ (): void

Returns​

void

Implementation of​

IMediaEffect.onUnload


pause​

▸ pause(): void

Returns​

void


play​

▸ play(): null | MediaStream

plays only if input stream is set

Returns​

null | MediaStream


render​

▸ render(): Promise<void>

Returns​

Promise<void>


setImage​

▸ setImage(image): Promise<boolean>

Set a background image

Parameters​

NameType
imageHTMLImageElement

Returns​

Promise<boolean>

boolean if succeeded, also triggers onfail event if not


setInput​

▸ setInput(stream?): void

Parameters​

NameType
stream?MediaStream

Returns​

void

Implementation of​

IMediaEffect.setInput


unload​

▸ unload(): void

Returns​

void


unsetImage​

▸ unsetImage(): void

Returns​

void


whenImageReady​

▸ whenImageReady(image): Promise<null | Error>

Parameters​

NameType
imageHTMLImageElement

Returns​

Promise<null | Error>