Voice Call
  • iOS
  • Android : Java
  • Web
  • Flutter
  • React Native
  • Electron
  • Unity3D
  • Cocos Creator
  • Windows
  • macOS
  • Linux
  • Overview
  • Develop your app
    • Quick start
    • Enhance basic feature
      • Use Tokens for authentication
      • Set up common audio config
      • Check the room connection status
  • Best practices
    • Implement a live audio room
  • Upgrade using advanced features
    • Advanced features
      • Configure the audio
        • Beautify & Change the voice
      • Improve audio quality
        • Test network and devices in advance
        • Monitor streaming quality
        • Visualize the sound level
      • Message signaling
        • Broadcast real-time messages to a room
        • Convey extra information using SEI
        • Quotas and limits
      • Play media files
        • Play media files
        • Play sound effects
      • Mix the streams
      • Record media data
      • Encrypt the streams
    • Distincitve features
      • Join multiple rooms
      • Customize the audio
      • Play streams via URL
      • Low-latency live streaming
  • Resources & Reference
    • SDK
    • Sample code
    • API reference
    • Debugging
    • FAQs
    • Key concepts
  • Documentation
  • Voice Call
  • Upgrade using advanced features
  • Advanced features
  • Record media data

Record local media data

Last updated:2023-05-17 19:00

Introduction

The local media recording component provides the capability of local media data recording, and records and stores audio and video data during the live broadcast to a local file.

Use cases

  • Local recording only: without publishing stream, local preview for recording only.
  • Recording while live broadcast: record while publishing the stream, and save the entire recording of the live broadcast to a local file.
  • Record short video during live broadcast: during live broadcast, you can record a short video at any time and save it locally.

Support formats

  • Audio and video: FLV, MP4
  • Pure audio: AAC

Prerequisites

Before you begin, make sure you complete the following:

  • Create a project in ZEGOCLOUD Admin Console and get the AppID and AppSign of your project.

  • Refer to the Quick Start doc to complete the SDK integration and basic function implementation.

Flow chart

The recording function api calling process is shown in the figure below:

TheRecording Function API Calling Process

Set Recording Function Callback

You need to call setDataRecordEventHandler to set recording function callback in order to receive and process recording information.

You will receive the set recording callback information after call startRecordingCapturedData to start recording.

// set recording function callback
engine.setDataRecordEventHandler(new IZegoDataRecordEventHandler(){

    public void onCapturedDataRecordStateUpdate (ZegoDataRecordState state, int errorCode, ZegoDataRecordConfig config, ZegoPublishChannel channel){
        // You can handle the logic of the state change during the recording process according to the error code or the recording state, such as UI prompts on the interface, etc.
        ...
    }

    public void onCapturedDataRecordProgressUpdate (ZegoDataRecordProgress progress, ZegoDataRecordConfig config, ZegoPublishChannel channel){
        // You can handle the logic of the progress change of the recording process according to the recording progress here, such as UI prompts on the interface, etc.
        ...
    }

});

Start Recording

You need to call startRecordingCapturedData to start recording.

Before starting recording, you need to call startPublishingStream to publish stream or call startPreview to preview, otherwise SDK cannot record successfully.

If you want to record audio and video, you should specify "ZegoDataRecordType.DEFAULT" or "ZegoDataRecordType.AUDIO_AND_VIDEO", if you want to record audio only, select "ZegoDataRecordType.ONLY_AUDIO", if you only record pure video, select "ZegoDataRecordType.ONLY_VIDEO".

  • In the configuration of the specified recording ZegoDataRecordConfig, the suffix of the file path must be end in ".mp4", ".flv" or ".aac" to specify the format of the recording file.
  • The recording type ZegoDataRecordType has nothing to do with the file extension.
// Apis called of loginRoom, startPublishingStream, startPreview, etc. here.
...

// new ZegoDataRecordConfig instance
ZegoDataRecordConfig config = new ZegoDataRecordConfig();
// Set recording file path, for example, .mp4 format.
config.filePath = "path.mp4";
// Set recording type
config.recordType = ZegoDataRecordType.DEFAULT;

// Start recording with the main channel.
engine.startRecordingCapturedData(config, ZegoPublishChannel.MAIN);

Stop Recording

You need to call stopRecordingCapturedData to stop recording。

During the recording process, if you exit the room logoutRoom SDK will automatically stop recording.

engine.stopRecordingCapturedData(ZegoPublishChannel.MAIN);

Playback of Recorded Files

There are two ways to play the recorded file.

  1. Call the system default player to play.
  2. Call the ZegoMediaPlayer component in ZegoExpressEngine to play.

FAQs

  1. What format of packaged files do local audio and video recording support?

    Currently, audio and video have supported FLV and MP4, and pure audio has supported AAC. The format is specified by the suffix of the file path. Among them, the MP4 format only supports AAC + H.264 encoding, and dissatisfaction will result in no picture or no audio.

  2. What are the requirements for the storage path?

    The stored path can be the file path that the application has permission to read and write. If the directory path is passed in, the file writing failure will be returned in the callback.

  3. How to get the size of the recording file during the recording process?

    You can get recording progress and recording file size by recording progress callback onCapturedDataRecordProgressUpdate.

  4. How does the SDK handle the file path of an existing file?

    There is no error, but the original file content will be cleared before writing.

  5. What should I pay attention to when recording with the function of video custom capture?

    When using the function of video custom capture, you also need to call SDK's startPreview before start recording.

  6. Why does my recorded video have green edges?

    The user needs to be careful not to modify the video encoding resolution during the recording process, and not to turn on the flow control (when it is turned on, the encoding resolution will be dynamically adjusted according to the network environment).

  7. Why do I stop publishing the stream during the recording process, and the recorded video will freeze for a moment?

    The internal processing method of the SDK cannot be solved for the time being. You are required to avoid such operations as much as possible.

  8. Does function of recording support the recording of "ZegoMediaPlayer/ZegoAudioPlayer/mixing" functions?

    You can record the sound of the above input sources, but only the sound mixed into the publishing stream will be recorded. If it is only played locally, it will not be recorded into the file.

Page Directory