Custom Video Capture
Feature Overview
Custom video Capture refers to the developer Capturing video by themselves and providing video data to ZEGO Express SDK, which is then encoded and published by ZEGO Express SDK.
When the following situations occur in the developer's business, it is recommended to use SDK's custom video Capture functionality:
- Ordinary camera Capture cannot meet requirements. For example, it contains a large amount of original business.
- Live streaming non-camera data. For example, video playback, screen sharing, game live streaming, etc.
- Using third-party virtual camera external Capture for custom beauty and other video preprocessing.
Example Source Code Download
Please refer to Download Example Source Code to get the source code.
For related source code, please check files in the "src/Examples/AdvancedVideoProcessing/CustomVideoCapture" directory.
Prerequisites
- A project has been created in ZEGOCLOUD Console, and valid AppID and Server address have been obtained. For details, please refer to Console - Project Information.
- ZEGO Express SDK has been integrated into the project, and basic audio/video streaming functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
Usage Steps
To publish a stream with a custom video source:
- When calling the createZegoStream interface to create a ZegoLocalStream stream instance object, specify the third-party data source by setting the "source" parameter.
- Call startPublishingStream to publish the stream.
-
Set third-party media stream
// Start previewing local video previewVideo.srcObject = mediaStream; const stream = await zg.createZegoStream({ custom: { video: { source: mediaStream }, audio: { source: mediaStream // Video original sound, can also be other audio source } } }) // Publish stream zg.startPublishingStream(idName, stream); -
Set third-party audio and video
- Third-party audio and video currently does not support Safari browser publishing, only playing.
- Since Chrome 86, when publishing third-party audio and video streams, if local audio and video are set to mute, the playing end will not be able to hear the corresponding sound.
When source is a <video> or <audio> object, use its specified video or audio source as preview.
// localVideo is <video> object
const stream = await zg.createZegoStream({
custom: {
video: {
source: localVideo
},
audio: {
source: localAudio // Can be video original sound, can also be other audio source
}
}
})
// Publish stream
zg.startPublishingStream(idName, stream);