Video Call
  • iOS
  • Android
  • Web : JavaScript
  • Flutter
  • React Native
  • Electron
  • Unity3D
  • Cocos Creator
  • Windows
  • macOS
  • Linux
  • Overview
  • Develop your app
    • Integrate the SDK
    • Implement a basic video call
    • Enhance basic feature
      • Use Tokens for authentication
      • Check the room connection status
      • Set up common video config
      • Set up common audio config
  • Best practices
    • Implement a video call for multiple users
  • Upgrade using advanced features
    • Advanced features
      • Configure the video
        • Improve your appearance in the video
        • Configure video codec
      • Improve video quality
        • Visualize the sound level
        • Monitor streaming quality
      • Message signaling
        • Broadcast real-time messages to a room
        • Quotas and limits
      • Share the screen
      • Mix the video streams
      • Publish multiple video streams
      • Replace the audio/video track
    • Distincitve features
      • Join multiple rooms
      • Customize the video and audio
      • Set the voice hearing range
      • Render the audio and video
      • Autoplay policy
      • Restrictions on playing multiple videos simultaneously in Safari
      • Play streams via URL
      • Browser compatibility
      • Audio mixing
      • Vitrual Background and Blur
    • Implement a video call using frameworks
      • Implement a video call using Vue
      • Implement a video call using Angular
      • Implement a video call using React
  • Resources & Reference
    • SDK
    • Sample codes
    • API reference
      • Client APIs
      • Server APIs
    • Debugging
      • Error codes
      • Logging/Version number
    • FAQs
    • Key concepts
  • Documentation
  • Video Call
  • Upgrade using advanced features
  • Distincitve features
  • Customize the video and audio
  • Customize how the video captures

Customize how the video captures

Last updated:2023-11-27 15:26

Introduction

When the ZEGOCLOUD SDK's default video capture module cannot meet your application's requirement, the SDK allows you to customize the video capture process. By enabling custom video capture, you can manage the video capture on your own and send the captured video data to the SDK for the subsequent video encoding and stream publishing. With custom video capture enabled, you can still call the SDK's API to render the video for local preview, which means you don't have to implement the rendering yourself.

Listed below are some scenarios where enabling custom video capture is recommended:

  • Your application needs to use a third-party beauty SDK. In such cases, You can perform video capture, and video preprocessing using the beauty SDK and then pass the preprocessed video data to the ZEGOCLOUD SDK for the subsequent video encoding and stream publishing.
  • Your application needs to perform another task that also needs to use the camera during the live streaming, which will cause a conflict with the ZEGOCLOUD SDK's default video capturing module. For example, it needs to record a short video clip during live streaming.
  • Your application needs to live stream with video data captured from a non-camera video source, such as a video file, a screen to be shared, or live video game content.

Prerequisites

Before you begin, make sure:

Implementation Steps

To publish a stream with a custom video source, you can set up the "source" parameter to specify the video source when calling createZegoStream to create the ZegoLocalStream. Then, call startPublishingStream to publish the stream.

  • Currently, using an <auido> or <video> object as the custom video source can only be played (can't be published) on the Safari browser.
  • Starting from Chrome 86, if a third-party media stream is used as the video source of a local stream and the local stream's audio is set to mute, the viewers will not be able to hear the sound when playing the stream.
  • Use a third-party media stream as the video source

    To push streams from custom video sources, you can create a ZegoLocalStream instance object by calling the createZegoStream interface, and specify the third-party data source by setting the "source" parameter. Then, call the startPublishingStream to publish the stream.

```javascript
//Start previewing the third-party media stream. 
previewVideo.srcObject = mediaStream;

// Use the third-party media stream as the video source to create a stream.
const stream = await zg.createZegoStream({
    custom: {
        video: {
            source: mediaStream
        },
        audio: {
            source: mediaStream
        }
    }
})
zg.startPublishingStream(idName, stream);
```
  • Use an Audio or Video object as the video source

    Call the createZegoStream interface to create a third-party audio and video stream, and then call the startPublishingStream interface to push the stream.

    Set the "source" parameter of the API createZegoStreamas a "custom" object, and assign the <audio> or <video> object to the "source" property of the "custom" object. The audio or video source of the <audio> or <video> object will also be used for local preview.

    // Use localVideo, a <video> object, as the video source to create a stream.
    const stream = await zg.createZegoStream({
        custom: {
            video: {
                source: localVideo
            },
            audio: {
                source: localVideo
            }
        }
    })
Page Directory