Skip to content

VideoMergePlugin

Video merge plugin

@geenee/armature!ShaderPlugin merges input video stream with the background texture. Merge is done by linear interpolation between images and interpolation weight (alpha) is a tunable input parameter that can be changed on runtime for smooth transition between streams. Background texture is allocated by the plugin and has the same size as the input stream, it can be accessed and updated on runtime, this, for example, allows to replace input video stream with a background video.

new VideoMergePlugin(alpha, mirror): VideoMergePlugin

Constructor

number = 0.5

Interpolation factor

boolean = false

Mirror background

VideoMergePlugin

ShaderPlugin.constructor

protected alpha: number = 0.5

Interpolation factor


protected optional bgTexture: ImageTexture

Background texture


protected optional fragSrc: string

Code of fragment shader (copy shader by default)

ShaderPlugin.fragSrc


protected optional inputs: string[]

Shader texture inputs (names of sampler uniforms)

ShaderPlugin.inputs


loaded: boolean

Loaded state

ShaderPlugin.loaded


protected mirror: boolean = false

Mirror background


ordinal: number

Ordinal number

ShaderPlugin.ordinal


protected optional renderer: Renderer<any>

Renderer loaded the plugin

ShaderPlugin.renderer


protected optional shader: ShaderProgram

Rendering shader

ShaderPlugin.shader


protected optional shaderCtx: WebGL2RenderingContext

Rendering context

ShaderPlugin.shaderCtx


protected size: Size

Image size

ShaderPlugin.size


protected optional uniforms: object

Shader uniforms as name-type map object

[key: string]: UniformType

ShaderPlugin.uniforms


protected optional vertSrc: string

Vertex shader source (copy shader by default)

ShaderPlugin.vertSrc

background(): undefined | ImageTexture

Background texture merged with the video

undefined | ImageTexture

Background texture


dispose(): void

Dispose video plugin

void

ShaderPlugin.dispose


load(renderer): Promise<void>

Initialize plugin

Initializes resources required for the shader effect. Allocates texture that will be merged with the video.

Renderer<any>

Renderer this plugin is attached to

Promise<void>

Promise resolving when initialization is finished

ShaderPlugin.load


process(result, input): Promise<boolean>

Process the image

Merges the video with a background texture.

any

Results of video processing

WebGLTexture

Current image texture

Promise<boolean>

True on success, false otherwise

ShaderPlugin.process


setAlpha(alpha): void

Set interpolation factor

number

Interpolation factor

void


setMirror(mirror): void

Set background mirror mode

boolean

Mirror flag

void


setupCamera(ratio, angle): void

Set camera parameters

Could be overridden to adjust plugin’s pipeline.

number

Aspect ration of input video

number

Vertical field of view in radians

void

ShaderPlugin.setupCamera


setupVideo(size): void

Set video size

Adjusts shader and texture to a new size.

Size

Resolution of input video

void

ShaderPlugin.setupVideo


unload(): void

Reset plugin

Releases all resources and instances created in load().

void

ShaderPlugin.unload


update(result, stream): Promise<void>

Sealed

Update the image

Main method implementing webgl shader effect or filter. ShaderRenderer keeps track of the current iamge texture that will be be rendered. ShaderPlugin uses the current texture as input and writes results to ShaderPlugin#output. ShaderPlugin#output becomes new current texture of ShaderRenderer. This way all ShaderPlugins attached to renderer organize a chain of effects applied on top of each other. Method process() implements shader effect itself, it’s intended to be overridden by effect authors.

any

Results of video processing

HTMLCanvasElement

Captured video frame

Promise<void>

Promise resolving when update is finished

ShaderPlugin.update