Skip to main content
Version: 2.0.x

Virtual Background - iOS

Virtual backgrounds enhance your live stream experience by allowing you to replace your physical background with a digital image or apply a blur effect. This is ideal for creators and streamers who want to maintain privacy, reduce distractions, or add a personal touch to their broadcast. You can use a preloaded background image or supply your own via a CDN.

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