Skip to content

Virtual Background

adamrangs edited this page Aug 8, 2022 · 1 revision

What is Virtual Background?

Virtual Background lets the user use a custom image as the background for the video. Users can also use the blur effect as the background. Users can set 3 types of virtual background None, Blur, and Custom. Example of same are given below:

Virtual Background Type

  1. None

This is equivalent to disable virtual background.

none
  1. Blur

This blurs the background as shown in the image below.

blur
  1. Custom

This lets the user use their own custom image as background.

none

Steps to use Virtual Background

  1. First check whether the device supports virtual background by using isVirtualBackgroundSupported: Bool, if this API returns true you can go ahead and use the feature.
  2. To fetch all the virtual backgrounds available use func fetchVirtualBackgrounds(completionHandler: @escaping (_ result: Result<[VirtualBackground]>) -> Void) API which will return array of VirtualBackground array. None and Blur type VirtualBackground is available by default.
  3. For uploading a custom background use func addVirtualBackground(image: LocalFile, completionHandler: @escaping (_ result: Result<VirtualBackground>) -> Void) API which will give you the VirtualBackground on completion.
  4. For setting the virtual background use func applyVirtualBackground(background: VirtualBackground, mode: VirtualBackgroundMode, completionHandler: @escaping (_ result: Result<Bool>) -> Void) specify the mode among preview or call as per requirement.
  5. To manage the virtual backgrounds use func removeVirtualBackground(background: VirtualBackground, completionHandler: @escaping (_ result: Result<Bool>) -> Void) API to delete a specific Custom VirtualBackground. None and Blur type cannot be deleted.
  6. You can modify the limit of custom virtual background supported by setting virtualBackgroundLimit: Int. The default limit is 3.

Notes

  • For adding custom background image types supported are JPG and PNG.
  • SDK will resize uploaded image to 1280x720, if the image size will be greater than 1280x720 to avoid CPU overhead.
  • Storage of application will be increased based on the images uploaded for virtual background
  • Virtual Background uses lots of CPU, once reached threshold limit Call.onCpuHitThreshold: (() -> Void)? will be fired, you can ask the user to disable the virtual background once this event triggers.