logo
On this page

Multi-Source Capture

2024-09-20

Feature Overview

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

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

  • The publishing channel supports setting multiple audio/video sources, but the same audio/video source can only be occupied by one channel.
  • The main channel's audio/video sources support dynamic switching and audio mixing capability. The auxiliary channel only supports specifying capture sources before publishing and does not support mixing.
  • When capturing screen, only iOS and Android platforms support simultaneous video and audio capture; other platforms only support video capture. If audio capture is needed, developers need to implement related logic themselves.

Example Source Code

Please refer to Download Example Source Code to get the source code.

For related source code, please check files in the "/ZegoExpressExample/Examples/Others/MultiVideoSource" directory.

Prerequisites

Before using the multi-source capture feature, ensure that:

Implementation Flow

Caution

Real-time audio products only support setting audio capture sources.

1 Create ZegoExpressEngine Engine

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

ZegoEngineProfile *profile = [[ZegoEngineProfile alloc] init];
profile.appID = [KeyCenter appID];
profile.appSign = [KeyCenter appSign];
profile.scenario = ZegoScenarioDefault;
[ZegoExpressEngine createEngineWithProfile:profile eventHandler:self];

2 Set Audio/Video Capture Sources

  1. Call the setVideoSource interface to set the video capture source.
/** Use camera as video capture source */
[[ZegoExpressEngine sharedEngine] setVideoSource:ZegoVideoSourceTypeCamera];
Note
  1. Call the setAudioSource interface to set the audio capture source.

    • Set audio capture source only

      /** Use microphone as audio capture source */
      [[ZegoExpressEngine sharedEngine] setAudioSource:ZegoAudioSourceTypeMicrophone];
    • Set audio capture source and mix configuration at the same time

      ZegoAudioSourceMixConfig *audioSourceMixConfig = [ZegoAudioSourceMixConfig defaultConfig];
      
      /** Mix the sound played by the media player with index 0 */
      audioSourceMixConfig.mediaPlayerCount = 1;
      audioSourceMixConfig.mediaPlayerIndexList = (int *)malloc(sizeof(int)*1);
      audioSourceMixConfig.mediaPlayerIndexList[0] = 0;
      
      /** Mix the sound played by the audio effect player with index 0 */
      audioSourceMixConfig.audioEffectPlayerCount = 1;
      audioSourceMixConfig.audioEffectPlayerIndexList = (int *)malloc(sizeof(int)*1);
      audioSourceMixConfig.audioEffectPlayerIndexList[0] = 0;
      
      /** Use microphone as audio capture source and set mix configuration */
      [[ZegoExpressEngine sharedEngine] setAudioSource:ZegoAudioSourceTypeMicrophone config:audioSourceMixConfig];
      
      free(audioSourceMixConfig.mediaPlayerIndexList);
      free(audioSourceMixConfig.audioEffectPlayerIndexList);
Note

3 Login to Room and Publish Stream

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

4 (Optional) Switch Audio/Video Capture Sources

  1. Call the setVideoSource interface to switch the video capture source.
/** Use screen sharing as video capture source */
[[ZegoExpressEngine sharedEngine] setVideoSource:ZegoVideoSourceTypeScreenCapture];
  1. Call the setAudioSource interface to switch the audio capture source.
/** Use media player as audio capture source */
[[ZegoExpressEngine sharedEngine] setAudioSource:ZegoAudioSourceTypeMediaPlayer];

5 Stop Publishing Stream

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

/** Stop publishing stream */
[[ZegoExpressEngine sharedEngine] stopPublishingStream];

FAQ

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

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

The limitations for combining video sources and audio sources 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/video source, the main channel needs to use and start the microphone device (enableMicrophone). If you don't need microphone sound on the main channel, you can disable audio publishing through mutePublishStreamAudio to keep the microphone started.
  3. Only when the main channel uses camera video source or microphone audio source, the auxiliary channel copying the main channel's video source or audio source can take effect.
  4. The main channel's audio source cannot be set to None, otherwise audio will not be able to render.

Previous

Network Speed Test

Next

Publish Multiple Streams

On this page

Back to top