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 { Pipeline, GaussianBlurBackgroundProcessor } from '@twilio/video-processors';

const blurBackground = new GaussianBlurBackgroundProcessor({
assetsPath: 'https://my-server-path/assets',
pipeline: Pipeline.WebGL2,
debounce: true,
});

blurBackground.loadModel().then(() => {
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
}).then(track => {
track.addProcessor(blurBackground, {
inputFrameBufferType: 'video',
outputFrameBufferContextType: 'webgl2',
});
});
});

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 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 | HTMLVideoElement

      The source of the input frame to process.

      OffscreenCanvas - Good for canvas-related processing that can be rendered off screen. Only works when using [[Pipeline.Canvas2D]].

      HTMLCanvasElement - This is recommended on browsers that doesn't support OffscreenCanvas, or if you need to render the frame on the screen. Only works when using [[Pipeline.Canvas2D]].

      HTMLVideoElement - Recommended when using [[Pipeline.WebGL2]] but works for both [[Pipeline.Canvas2D]] and [[Pipeline.WebGL2]].

    • outputFrameBuffer: HTMLCanvasElement

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

    Returns Promise<void>

Generated using TypeDoc