Virtual Background enables users to blur their background, or replace it with a solid color or an image. This feature is applicable to scenarios such as online conferences, online classes, and live streaming. It helps protect personal privacy and reduces audience distraction.
Virtual Background offers the following options:
Feature Example Blurred background and image background Video/Animated background Your browser does not support the video
element. Portrait-in-picture Allows the presenter to use slides as the virtual background while superimposing their video. The effect is similar to a weather news cast on television, preventing interruptions during a layout toggle.
Want to test Virtual Background? Try the online demo .
Ensure that you have implemented the SDK quickstart in your project.
This section shows you how to add a virtual background to the local video.
To avoid performance degradation or unavailable features when enabling Virtual Background on low-end devices, check whether the device supports the feature.
boolean isFeatureAvailable () {
return agoraEngine . isFeatureAvailableOnDevice (
Constants . FEATURE_VIDEO_VIRTUAL_BACKGROUND
Copy To blur the video background, use the following code:
void setBlurBackground () {
VirtualBackgroundSource virtualBackgroundSource = new VirtualBackgroundSource ();
virtualBackgroundSource . setBackgroundSourceType ( VirtualBackgroundSource . BACKGROUND_BLUR );
virtualBackgroundSource . setBlurDegree ( VirtualBackgroundSource . BLUR_DEGREE_MEDIUM );
// Set processing properties for background
SegmentationProperty segmentationProperty = new SegmentationProperty ();
segmentationProperty . setModelType ( SegmentationProperty . SEG_MODEL_AI );
// Use SEG_MODEL_GREEN if you have a green background
segmentationProperty . setGreenCapacity ( 0.5f ); // Accuracy for identifying green colors (range 0-1)
// Enable or disable virtual background
agoraEngine . enableVirtualBackground (true, virtualBackgroundSource , segmentationProperty );
Copy To apply a solid color as the virtual background, use a hexadecimal color code. For example, 0x0000FF
for blue:
void setSolidBackground () {
VirtualBackgroundSource virtualBackgroundSource = new VirtualBackgroundSource ();
virtualBackgroundSource . setBackgroundSourceType ( VirtualBackgroundSource . BACKGROUND_COLOR );
virtualBackgroundSource . setColor ( 0x0000FF );
// Set processing properties for background
SegmentationProperty segmentationProperty = new SegmentationProperty ();
segmentationProperty . setModelType ( SegmentationProperty . SEG_MODEL_AI );
// Use SEG_MODEL_GREEN if you have a green background
segmentationProperty . setGreenCapacity ( 0.5f ); // Accuracy for identifying green colors (range 0-1)
// Enable or disable virtual background
agoraEngine . enableVirtualBackground (true, virtualBackgroundSource , segmentationProperty );
Copy To set a custom image as the virtual background, specify the absolute path to the image file.
void setImageBackground () {
VirtualBackgroundSource virtualBackgroundSource = new VirtualBackgroundSource ();
virtualBackgroundSource . setBackgroundSourceType ( VirtualBackgroundSource . BACKGROUND_IMG );
virtualBackgroundSource . setSource ( " <absolute path to an image file> " );
// Set processing properties for background
SegmentationProperty segmentationProperty = new SegmentationProperty ();
segmentationProperty . setModelType ( SegmentationProperty . SEG_MODEL_AI );
// Use SEG_MODEL_GREEN if you have a green background
segmentationProperty . setGreenCapacity ( 0.5f ); // Accuracy for identifying green colors (range 0-1)
// Enable or disable virtual background
agoraEngine . enableVirtualBackground (true, virtualBackgroundSource , segmentationProperty );
Copy To disable the virtual background and revert to the original video state, use the following code:
void removeBackground () {
// Disable virtual background
agoraEngine . enableVirtualBackground (
new VirtualBackgroundSource (),
new SegmentationProperty ()
Copy
This section contains content that completes the information in this page, or points you to documentation that explains other aspects to this product.