Custom video pre-processing refers to processing the captured video with the AI Effects SDK for features such as face beautification, and stickers, this might be needed when the Video Call SDK does not meet your development requirements.
)
Compared to the custom video capture feature,
the custom video pre-processing does not require you to manage the device input sources, you only need to manipulate the raw data thrown out by the ZegoExpress-Video SDK, and then send it back to the ZegoExpress-Video SDK.
For more advanced features such as layer blending, we recommend you refer to the Customize how the video captures.
Before you begin, make sure you complete the following:
Create a project in ZEGOCLOUD Admin Console and get the AppID and AppSign of your project.
Refer to the Quick Start doc to complete the SDK integration and basic function implementation.
The following diagram shows the API call sequence of the custom video pre-processing:
)
Create a ZegoCustomVideoProcessConfig object and set the bufferType property to specify the type of video frame data provided to the Express SDK.
Currently, the Android SDK supports the following three bufferType values. Setting other enumeration values will not work properly:
| Buffer Type | Enumeration Value | Description |
|---|---|---|
| GLTexture2D | ZegoVideoBufferType.GL_TEXTURE_2D | Raw video frame data in the form of OpenGL Texture 2D. |
| SurfaceTexture | ZegoVideoBufferType.SURFACE_TEXTURE | Raw video frame data in the form of SurfaceTexture. |
| GLTexture2DAndRawData | ZegoVideoBufferType.GL_TEXTURE_2D_AND_RAW_DATA | Both OpenGL Texture 2D frames and raw data frames. |
Before starting the local video preview and stream publishing, call the enableCustomVideoProcessing method to enable the custom video pre-processing feature.
The following example demonstrates how to enable custom video pre-processing with ZegoVideoBufferType.GL_TEXTURE_2D:
ZegoCustomVideoProcessConfig config = new ZegoCustomVideoProcessConfig();
// Specify the GL_TEXTURE_2D type for video frame data.
config.bufferType = ZegoVideoBufferType.GL_TEXTURE_2D;
// Enable custom video pre-processing.
express.enableCustomVideoProcessing(true, config, ZegoPublishChannel.MAIN);
Call the setCustomVideoProcessHandler method to register a custom video pre-processing callback and implement the onCapturedUnprocessedTextureData and other related callback methods.
Once the SDK captures raw video frames, it notifies the developer through the onCapturedUnprocessedTextureData callback.
You can process the raw video frames using:
If you are using a third-party beauty SDK or manually allocating memory, please:
// Register the callback to retrieve and process raw data.
express.setCustomVideoProcessHandler(new IZegoCustomVideoProcessHandler() {
...
// Receive the texture from the ZegoExpressEngine.
@Override
public void onCapturedUnprocessedTextureData(int textureID, int width, int height, long referenceTimeMillisecond, ZegoPublishChannel channel) {
ZegoEffectsVideoFrameParam param = new ZegoEffectsVideoFrameParam();
param.format = ZegoEffectsVideoFrameFormat.BGRA32;
param.width = width;
param.height = height;
// Perform custom pre-processing using the Effects SDK.
int processedTextureID = effects.processTexture(textureID, param);
// Send the processed buffer back to the Express SDK.
express.sendCustomVideoProcessedTextureData(processedTextureID, width, height, referenceTimeMillisecond);
}
});
