The video call service provided by ZEGOCLOUD enables you to build audio and video applications through its flexible and easy-to-use API. Meanwhile, another ZEGOCLOUD add-on: AI Effects, is based on the AI algorithm, which enables you to implement a series of beautification features such as face beautification, face shape retouch, and other features.
These two services can be combined by using the two types of SDK together to create a real-time application with beautification features, which can be widely used in entertainment live streaming, live game streaming, video conference, and other live streaming scenarios.
Basic concepts
The ZegoExpress-Video SDK (Hereafter called the Express SDK): The video call SDK provided by ZEGOCLOUD. This SDK enables you to implement real-time audio and video features, in live streaming, live co-hosting streaming, and other scenarios.
The ZegoEffects SDK (Hereafter called the Effects SDK): The AI effects SDK provided by ZEGOCLOUD provides the AI-based image rendering and algorithm abilities that enable you to implement face beautification, face shape retouch, background segmentation, face detection, and other features.
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 overall process of the combination of the two SDKs is as follows:
Before using the AI features of the Effects SDK, you need to import the resources or models required for those features.
// Specify the absolute path of the face recognition model, which is required for features such as face detection, eyes enlarging, and face slimming.
ArrayList<String> aiModeInfos = new ArrayList<>();
aiModeInfos.add("sdcard/xxx/xxxxx/FaceDetectionModel.bundle");
aiModeInfos.add("sdcard/xxx/xxxxx/Segmentation.bundle");
// Specify the absolute path of the resources.
ArrayList<String> aiResources = new ArrayList<>();
aiResources.add("sdcard/xxx/xxxxx/PendantResources.bundle");
aiResources.add("sdcard/xxx/xxxxx/FaceWhiteningResources");
// Set the path list for resources or models, which must be called before calling the `create` method to create a ZegoEffects object.
ZegoEffects.setResources(aiResources);
For all resources and models that the Effects SDK supports, see Import resources and models.
Pass the AppID and AppSign obtained from the Prerequisites directly to the create interface. After internal authentication by the SDK, it will create an Effects object and return the corresponding error code.
ZegoEffects mEffects;
long appid = *******;
String appSign = "*******";
ZegoEffects.create(appid, appSign, applicationContext, (effects, errorCode) -> {
mEffects = effects;
//Execute custom logic
});
Call the create interface, pass in the authentication file obtained from the Prerequisites to create an Effects object.
// Pass in the authentication file you obtained.
ZegoEffects effects = ZegoEffects.create("ABCDEFG", getApplication());
To initialize the Effects SDK object, call the initEnv
method, and pass in the width and height of the incoming video data to be processed.
The following is an example of processing 1280 × 720 video images:
// Initialize the Effects SDK object, nd pass in the width and height of the incoming video data to be processed.
effects.initEnv(1280, 720);
To initialize the Express SDK, call the createEngine
method.
/** Define a ZegoExpressEngine object */
ZegoExpressEngine engine;
ZegoEngineProfile profile = new ZegoEngineProfile();
/** AppID format: 123456789L */
profile.appID = appID;
/** General scenario */
profile.scenario = ZegoScenario.GENERAL;
/** Set application object of App */
profile.application = getApplication();
/** Create a ZegoExpressEngine instance */
engine = ZegoExpressEngine.createEngine(profile, null);
The Express SDK provides two methods to get the video raw data:
The difference between the two methods is as follows, you can choose based on the actual situation:
Method | Description | Advantages |
---|---|---|
Custom video pre-processing |
The ZEGO Express SDK collects the video raw data. |
Together with the Express SDK and the Effects SDK, you do not need to manage the device input sources, but simply manipulate the raw data thrown by the Express SDK and pass it back to the Express SDK. |
Custom video capture |
Capture the video raw data by yourself. |
When multiple manufacturers are taken on, services can be flexibly implemented and performance optimization can be improved. |
To capture the video raw data using this method, do the following:
a. Select the GL_TEXTURE_2D
video frame data type, and set the buffer type as RGBA32
.
b. Call the enableCustomVideoProcessing
method to enable the custom video pre-processing.
c. The SDK sends out the captured video raw data through the callback onCapturedUnprocessedTextureData
.
ZegoCustomVideoProcessConfig config = new ZegoCustomVideoProcessConfig();
// Select the [GL_TEXTURE_2D] video frame data type.
config.bufferType = ZegoVideoBufferType.GL_TEXTURE_2D;
// Enable the custom video pre-processing.
express.enableCustomVideoProcessing(true, config, ZegoPublishChannel.MAIN);
For details, see Custom video pre-processing.
For details, see Custom video capture.
In the corresponding callback for receiving the video raw data, the Effects SDK can be used to implement AI features.
After implemented the AI features, the Express SDK encodes and publishes the processed data and sends it to the cloud server. At this time, the remote user can play the processed video streams.
onCapturedUnprocessedTextureData
callback.// Take using the custom video pre-processing method as an example.
// Obtain the raw video data with callback.
// Set the callback.
express.setCustomVideoProcessHandler(new IZegoCustomVideoProcessHandler() {
...
// Receive texture from ZegoExpressEngine
@Override
public void onCapturedUnprocessedTextureData(int textureID, int width, int height, long referenceTimeMillisecond, ZegoPublishChannel channel) {
ZegoEffectsVideoFrameParam param = new ZegoEffectsVideoFrameParam();
param.format = ZegoEffectsVideoFrameFormat.RGBA32;
param.width = width;
param.height = height;
// Process buffer by ZegoEffects
int processedTextureID = effects.processTexture(textureID, param);
// Send processed texture to ZegoExpressEngine
express.sendCustomVideoProcessedTextureData(processedTextureID, width, height, referenceTimeMillisecond);
}
}
To adjust the AI effects during the stream publishing and playing operation, use the Effects SDK to make changes in real time.
// Enable the skin tone enhancement feature.
effects.enableWhiten(true);
// Set the whitening intensity. The value range is [0, 100], and the default value is 50.
ZegoEffectsWhitenParam param = new ZegoEffectsWhitenParam();
param.intensity = 100;
effects.setWhitenParam(param);
For more AI features, see Face beautification, Face shape retouch, Backgroud segmentation, Face detection, Stickers, and Filters.