Skip to main content
Version: 2.0.x

Virtual Background - iOS

Virtual backgrounds let you replace your real background during video calls or meetings with a digital image or video. This can be useful for:

  • Privacy: Hide your messy room or anything you don't want others to see.

  • Focus: Minimize distractions and keep the focus on the conversation.

  • Fun: Liven up the call with a cool background theme.

Virtual Background using VideoSDKBackgroundProcessor

This is the easiest way to enable virtual backgrounds in your app. VideoSDK provides a handy class called VideoSDKBackgroundProcessor that takes care of replacing your background for you. Here's a step-by-step guide:

Toggle Virtual Background

  • Virtual background can be enabled by setting VideoSDK's VideoSDKBackgroundProcessor's instance using the setVideoProcessor method of Meeting class.

  • To disbale the virtual background, simply pass nil in setVideoProcessor and virtual background will be replaced with the normal camera stream.

Example Code:

class MeetingViewController {
//variable for keeping track of Virtual Background
var isVirtualBackground: Bool = false

// source url for the background image (make sure background is in portrait, else might get undesired output).
let backgroundSource = URL(string: "https://cdn.videosdk.live/virtual-background/cloud.jpeg")!
//create an inctance of VideoSDKBackgroundProcessor
let processor = VideoSDKBackgroundProcessor(backgroundSource: backgroundSource)

// Button when tapped will toggle the virtual background for local participant
@IBAction func toggleVirtualBackground(_ sender: Any) {

if isVirtualBackground {
// Turn off virtual background
meeting.setVideoProcessor(processor: nil)
isVirtualBackground = false
} else {
// Turn on virtual background
meeting.setVideoProcessor(processor: processor)
isVirtualBackground = true
}
}
}

Changing Background Image

You can also change the background image dynamically using the changeBackground method of the VideoSDKBackgroundProcessor class.

class MeetingViewController {
// processor instance
// let processor = VideoSDKBackgroundProcessor()

// Button when tapped will toggle the virtual background for local participant
@IBAction func changeBackgroundTapped(_ sender: Any) {
// URL of new background image
let backgroundSource = URL(string: "https://cdn.videosdk.live/virtual-background/san-fran.jpeg")!

// Call changeBackground method of VideoSDKBackgroundProcessor
self.processor.changeBackground(backgroundSource: backgroundSource)
}
}

API Reference

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord