logo
Video Call
On this page

Publishing Multiple Streams Simultaneously

2024-01-02

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.
Note

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:

Usage Steps

  1. Call getVideoDeviceList to get the list of available video devices.
  2. Call the useVideoDevice interface to specify the video device for the main stream, and call the startPublishingStream interface to publish the main stream.
  3. 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.

Previous

Multi-Source Capture

Next

Supplemental Enhancement Information (SEI)

On this page

Back to top