logo
On this page

Multi-Source Capture

2024-09-20

Function Overview

Multi-source capture is used to manage audio and video source configurations for each channel. Through this capability, you can flexibly and quickly implement real-time interaction of different audio and video content, such as screen sharing, audio mixing, and other functions.

The main capabilities and limitations of multi-source capture are as follows:

  • The publishing channel supports setting multiple audio and video sources, but the same audio and video source can only be occupied by one channel.
  • The main channel's audio and video sources support dynamic switching and also support audio mixing capabilities. The auxiliary channel only supports specifying capture sources before publishing stream, and does not support audio mixing.
  • When capturing screen, only iOS and Android platforms support capturing both video and audio at the same time; other platforms only support capturing video. If you need to capture audio, please implement the relevant logic yourself.

Prerequisites

Before using the multi-source capture function, please ensure:

Implementation Flow

Warning

Voice Call products only support setting audio capture sources.

1 Create ZegoExpressEngine engine

For the process of creating ZegoExpressEngine engine, please refer to Create Engine for implementing video call.

// Create ZegoExpress instance, listen to common events
void CreateEngine() {
    // Create engine, general scenario access
    ZegoEngineProfile profile = new ZegoEngineProfile();
    profile.appID = appID;  // Please obtain through official website registration, format: 1234567890L
    profile.appSign = appSign; // Please obtain through official website registration, format: @"0123456789012345678901234567890123456789012345678901234567890123" (total 64 characters)
    profile.scenario = ZegoScenario.Broadcast;  // Specify using live streaming scenario (please fill in the scenario suitable for your business according to actual situation)

    engine = ZegoExpressEngine.CreateEngine(profile);
}

2 Set audio and video capture sources

  1. Call the SetVideoSource interface to set the video capture source.

    /** Use camera as video capture source */
    engine.SetVideoSource(ZegoVideoSourceType.Camera);
Note
  • If you need to use custom video capture as the video capture source, you need to set the video capture source type to ZegoVideoSourceTypeCustom, call the EnableCustomVideoCapture interface to set the video frame data type to be sent, and call the SendCustomVideoCaptureRawData interface to send video frame data to the SDK.
  • If you need to use media player as the video capture source, you need to call the CreateMediaPlayer interface to create a media player first, then set the video capture source type to ZegoVideoSourceTypePlayer and set the media player instance index used by the video capture source by calling the SetVideoSource interface, and then use the newly created media player to load resources and play. For details, please refer to Media Player.
  • If you need to use screen sharing as the video capture source, you need to set the video capture source type to ZegoVideoSourceTypeScreenCapture and enable screen sharing to push screen shared video data to the SDK. For details, please refer to Screen Sharing.
  1. Call the SetAudioSource interface to set the audio capture source.

    • Set audio capture source only
    /** Use microphone as audio capture source */
    engine.SetAudioSource(ZegoAudioSourceType.Microphone);
    • Set audio capture source and set audio mixing configuration at the same time
    ZegoAudioSourceMixConfig audioSourceMixConfig = new ZegoAudioSourceMixConfig();
    
    /** Mix in the sound played by the media player with index 0 */
    audioSourceMixConfig.mediaPlayerIndexList = new List<int>();
    audioSourceMixConfig.mediaPlayerIndexList.Add(0);
    
    /** Mix in the sound played by the audio effect player with index 0 */
    audioSourceMixConfig.audioEffectPlayerIndexList = new List<int>();
    audioSourceMixConfig.audioEffectPlayerIndexList.Add(0);
    
    /** Use microphone as audio capture source and set audio mixing configuration */
    engine.SetAudioSource(ZegoAudioSourceType.Microphone, audioSourceMixConfig);
Note

3 Login room and publish stream

For the process of logging in to room and publishing stream, please refer to Login Room and Publish Stream for implementing video call.

4 (Optional) Switch audio and video capture sources

  1. Call the SetVideoSource interface to switch the video capture source.

    /** Use screen sharing as video capture source */
    engine.SetVideoSource(ZegoVideoSourceType.ScreenCapture);
  2. Call the SetAudioSource interface to switch the audio capture source.

    /** Use media player as audio capture source */
    engine.SetAudioSource(ZegoAudioSourceType.Player);

5 End publishing stream

For the process of ending publishing stream, please refer to Stop Streaming for implementing video call.

/** Stop publishing stream */
engine.StopPublishingStream();

FAQ

  1. How to capture screen video and system audio?

If you need to capture screen video and system audio, please refer to Screen Sharing.

  1. Is setting multiple media players supported?

Yes, but note that the same player instance can only be occupied by one channel.

  1. What are the limitations when using video sources and audio sources in combination?

The limitations for using video sources and audio sources in combination are as follows:

  1. The main channel cannot use the media player's video or audio source.
  2. When the auxiliary channel uses a media player as the audio and video source, the main channel needs to use and start the microphone device (enableMicrophone). If you do not need microphone sound on the main channel, you can disable audio publishing to keep the microphone started through mutePublishStreamAudio.
  3. Only when the main channel uses camera video source or microphone audio source, the auxiliary channel copying the main channel video source or audio source can take effect.
  4. The audio source of the main channel cannot be set to None, otherwise the audio cannot be rendered.

Previous

Call Quality Monitoring

Next

Supplemental Enhancement Information (SEI)

On this page

Back to top