Docs / Android / ZEGOCLOUD
ZEGOCLOUD on Android
Beautify the published camera of a ZEGOCLOUD Express 3.x call with custom video processing on ZEGO's GL thread.
Demo app: facevity-android-demo on GitHub
ZEGOCLOUD’s custom video processing hands you each captured frame as an OpenGL texture on its own GL thread. Facevity processes it there with the texture path, so no YUV conversion is needed.
1. Requirements
- Facevity for Android 0.3.3 set up as in the quick start
- ZEGOCLOUD Express SDK 3.x
- Licence feature
beauty.basic(texture path:buffer.pathis not needed)
2. The handler
ZEGO calls the handler on its GL thread with an upright, unmirrored 2D texture, so the rotation is 0.
class ZegoFacevity(private val engine: ZegoExpressEngine, private val fv: Facevity) :
IZegoCustomVideoProcessHandler() {
override fun onCapturedUnprocessedTextureData(
textureID: Int, width: Int, height: Int, referenceTimeMillisecond: Long, channel: ZegoPublishChannel,
) {
val out = fv.processTexture(
TextureFrame(textureID, false, width, height, 0, false, referenceTimeMillisecond * 1_000_000)
)
engine.sendCustomVideoProcessedTextureData(out, width, height, referenceTimeMillisecond, channel)
}
override fun onStop(channel: ZegoPublishChannel) {
fv.onGlContextDestroyed() // on ZEGO's GL thread
}
}
processTexture returns the input id when there is nothing to do (beauty off, all levels 0), so the frame goes out unchanged.
3. Enable it before preview and publishing
val fv = Facevity.initialize(context)
fv.setParams(BeautyParams.NATURAL)
engine.enableCustomVideoProcessing(true, ZegoCustomVideoProcessConfig().apply {
bufferType = ZegoVideoBufferType.GL_TEXTURE_2D
})
engine.setCustomVideoProcessHandler(ZegoFacevity(engine, fv))
engine.startPreview(ZegoCanvas(previewView))
engine.startPublishingStream(streamId)
Custom video processing must be enabled before startPreview and startPublishingStream. Preview and publish both use the processed texture.
4. Tear down
engine.stopPublishingStream()
engine.stopPreview()
engine.setCustomVideoProcessHandler(null)
fv.release()
Notes
- The texture returned by
processTextureis owned by the engine and stays valid until the call after next. - Facevity saves and restores the GL state it touches, so ZEGO’s own rendering is not affected.
Next: LiveKit on Android · all platforms
Need help with an integration? Contact the Facevity team. We answer integration questions during trials.