Publishing Multiple Streams Simultaneously
Introduction
The Express SDK provides the ability to publish multiple streams simultaneously. When the following situations occur in the developer's business, it is recommended to use the SDK's multi-stream publishing feature:
- Game streamers publish camera footage on the main stream and screen capture footage on the second stream.
- Outdoor streamers publish front camera footage on the main stream and rear camera footage on the second stream.
Currently, the SDK supports a maximum of 4 publishing channels. Versions before 2.14.0 have a default maximum of 2 publishing channels. If you need to support more publishing channels, please contact ZEGOCLOUD Technical Support for special packaging.
Download Sample Source Code
Please refer to Download Sample Source Code to obtain the source code.
For related source code, please check the files in the "/ZegoExpressExample/Examples/AdvancedStreaming/PublishingMultipleStreams" directory.
Prerequisites
Before implementing the multi-stream publishing feature, ensure that:
- A project has been created in the ZEGOCLOUD Console, and valid AppID and AppSign have been obtained. For details, please refer to Console - Project Information.
- ZEGO Express SDK has been integrated into the project, and basic audio and video streaming functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.
Usage Steps
- Call getVideoDeviceList to get the list of available video devices.
- Call the useVideoDevice interface to specify the video device for the main stream, and call the startPublishingStream interface to publish the main stream.
- Call the useVideoDevice interface to specify the video device for the second stream, and call the startPublishingStream interface to publish the second stream.
// Get available video devices
auto videoDeviceList = engine->getVideoDeviceList();
// Specify video device for main stream then start publishing main stream
engine->useVideoDevice(videoDeviceList[0].deviceID, ZEGO_PUBLISH_CHANNEL_MAIN);
engine->startPublishingStream("stream1", ZEGO_PUBLISH_CHANNEL_MAIN);
// Specify video device for second stream then start publishing second stream
// Auxiliary channel does not capture by default, need to set the video source (using experimental API)
std::string params = "
{
\"method\":\"express.video.set_video_source\",
\"params\":{
\"source\":2,
\"channel\":1
}
}";
engine->callExperimentalAPI(params);
engine->useVideoDevice(videoDeviceList[1].deviceID, ZEGO_PUBLISH_CHANNEL_AUX);
engine->startPublishingStream("stream2", ZEGO_PUBLISH_CHANNEL_AUX);FAQ
Does it support publishing more than 4 streams simultaneously?
To work with the real-time signaling feature, the SDK currently supports a maximum of 4 publishing channels by default, but versions before 2.14.0 have a default maximum of 2 publishing channels. If you need to support more publishing channels, please contact ZEGOCLOUD Technical Support for special packaging.
