Remove backgrounds with an alpha channel
The code on this page works with either the default UI or the custom UI.
Meeting hosts who hold a raw streaming token can enable alpha channel mode, which requests that Zoom send both the original video data and a mask demarking the edge of a participant's body. The SDK can then use the alpha mask and raw data to remove the participant's background and render meeting participants natively in the host's virtual world.
Add new methods
Add a new method to the MobileRTCMeetingDelegate.h class.
/*!
@brief Callback event of alpha channel mode changes.
@param alphaChannelOn YES means it's in alpha channel mode. Otherwise, it's not.
*/
- (void)onVideoAlphaChannelStatusChanged:(BOOL)alphaChannelOn;
This callback is triggered when alpha channel mode is turned on.
Add these methods to the MobileRTCMeetingService+Video.h class.
/*!
@brief Determine if alpha channel mode can be enabled.
@return YES means it can be enabled. Otherwise NO. Only for host call.
@warning Only host can enable alpha channel.
*/
- (BOOL)canEnableAlphaChannelMode;
/*!
@brief Enable or disable alpha channel mode.
@param enable YES indicates to enable alpha channel mode., Otherwise, disable it.
@return If the function succeeds, the return value is MobileRTCSDKError_Success. Otherwise failed.
@warning Only host can enable alpha channel.
@warning This function will enable the meeting alpha channel, even if the current iOS device not support alpha channel.
@warning for iOS device should be iPhone 8/ 8 plus X or above or be iPad Pro 9.7 above, OS should be iOS 11 or above.
*/
- (MobileRTCSDKError)enableAlphaChannelMode:(BOOL)enable;
/*!
@brief Determine if alpha channel mode is enabled.
@return YES indicates is in alpha channel mode. Otherwise NO.
*/
- (BOOL)isAlphaChannelModeEnabled;
Enable alpha channel mode
Before enabling the alpha channel, call canEnableAlphaChannelMode to check whether the alpha channel mode is enabled.
To enable or disable the alpha channel, call EnableAlphaChannelMode.
Add a new method to the class MobileRTCVideoRawData.h.
/*!
@brief The data pointer to a video's alpha data.
*/
@property (nonatomic, assign) char *alphaBuffer;
/*!
@brief the alpha buffer data length
*/
@property (nonatomic, assign) unsigned int alphaBufferLen;
The raw data will have two more values after performing these steps: GetAlphaBuffer for the alpha data buffer, and another, GetAlphaBufferLen, for the alpha data buffer length.
Now that you've received the data, edit the raw data.