Class GaussianBlurBackgroundProcessor

The GaussianBlurBackgroundProcessor, when added to a VideoTrack, applies a gaussian blur filter on the background in each video frame and leaves the foreground (person(s)) untouched. Each instance of GaussianBlurBackgroundProcessor should be added to only one VideoTrack at a time to prevent overlapping of image data from multiple VideoTracks.

Example

import { createLocalVideoTrack } from 'twilio-video';
import { GaussianBlurBackgroundProcessor } from '@twilio/video-processors';

let blurBackground: GaussianBlurBackgroundProcessor;

(async() => {
blurBackground = new GaussianBlurBackgroundProcessor({
assetsPath: 'https://my-server-path/assets'
});
await blurBackground.loadModel();

const track = await createLocalVideoTrack({
// Increasing the capture resolution decreases the output FPS
// especially on browsers that do not support SIMD
// such as desktop Safari and iOS browsers, or on Chrome
// with capture resolutions above 640x480 for webgl2.
width: 640,
height: 480,

// Any frame rate above 24 fps on desktop browsers increase CPU
// usage without noticeable increase in quality.
frameRate: 24
});
track.addProcessor(virtualBackground, {
inputFrameBufferType: 'videoframe',
outputFrameBufferContextType: 'bitmaprenderer'
});
})();

Hierarchy

  • BackgroundProcessor
    • GaussianBlurBackgroundProcessor

Constructors

Accessors

  • get blurFilterRadius(): number
  • The current background blur filter radius in pixels.

    Returns number

  • set blurFilterRadius(radius): void
  • Set a new background blur filter radius in pixels.

    Parameters

    • radius: number

    Returns void

  • get deferInputFrameDownscale(): boolean
  • Whether the pipeline is calculating the person mask without waiting for the current input frame to be downscaled (Chrome only).

    Returns boolean

  • set deferInputFrameDownscale(defer): void
  • Toggle whether the pipeline should calculate the person mask without waiting for the current input frame to be downscaled (Chrome only).

    Parameters

    • defer: boolean

    Returns void

  • get maskBlurRadius(): number
  • The current blur radius when smoothing out the edges of the person's mask.

    Returns number

  • set maskBlurRadius(radius): void
  • Set a new blur radius to be used when smoothing out the edges of the person's mask.

    Parameters

    • radius: number

    Returns void

Methods

  • Load the segmentation model. Call this method before attaching the processor to ensure video frames are processed correctly.

    Returns Promise<void>

  • Apply a transform to the background of an input video frame and leaving the foreground (person(s)) untouched. Any exception detected will result in the frame being dropped.

    Parameters

    • inputFrameBuffer: OffscreenCanvas | HTMLCanvasElement | VideoFrame | HTMLVideoElement

      The source of the input frame to process.

      OffscreenCanvas - Good for canvas-related processing that can be rendered off screen.

      HTMLCanvasElement - This is recommended on browsers that doesn't support OffscreenCanvas, or if you need to render the frame on the screen.

      HTMLVideoElement

      VideoFrame - Recommended on browsers that support the Insertable Streams API.

    • outputFrameBuffer: HTMLCanvasElement

      The output frame buffer to use to draw the processed frame.

    Returns Promise<void>

Generated using TypeDoc