Video Call
  • iOS : Objective-C
  • Android
  • Web
  • 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
      • Config your video based on scenes
      • 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
        • Watermark the video/Take snapshots
        • Improve your appearance in the video
        • Beautify & Change the voice
        • Configure video codec
        • Output the video in H.265
      • Improve video quality
        • Configure bandwidth management
        • Test network and devices in advance
        • Visualize the sound level
        • Monitor streaming quality
      • Message signaling
        • Convey extra information using SEI
        • Broadcast real-time messages to a room
        • Quotas and limits
      • Play media files
        • Play media files
        • Play sound effects
      • Share the screen
      • Mix the video streams
      • Publish multiple video streams
      • Encrypt the video streams
      • Record video media data
    • Distincitve features
      • Join multiple rooms
      • Customize the video and audio
      • Set the voice hearing range
      • Use the bit mask
      • Play streams via URL
      • Play a transparent gift special effect
  • Upgrade using Add-on
  • 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
  • Advanced features
  • Record video 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 implementing the function, please make sure:

  • ZEGO Express SDK has been integrated into the project to implement basic real-time audio and video functions. For details, please refer to Quick start .
  • A project has been created in ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - Project Information .

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 callback
[[ZegoExpressEngine sharedEngine] setDataRecordEventHandler:self];
// The developer can handle the logic of the state change of the recording process according to the error code or recording state here, such as UI prompts on the interface, etc.
-(void)onCapturedDataRecordStateUpdate:(ZegoDataRecordState)state errorCode:(int)errorCode config:(ZegoDataRecordConfig *)config channel:(ZegoPublishChannel)channel {
    NSLog(@" Record state update, state: %d, errorCode: %d, file path: %@, record type: %d", (int)state, errorCode, config.filePath, (int)config.recordType) ;
}

// The developer 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.
-(void)onCapturedDataRecordProgressUpdate:(ZegoDataRecordProgress *)progress config:(ZegoDataRecordConfig *)config channel:(ZegoPublishChannel)channel {
    NSLog(@" Record progress update, duration: %llu, file size: %llu", progress.duration, progress.currentFileSize);
}

 

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.

  • ZegoPublishChannel specify the recording media channel, if you only publish one stream or only do a local preview, you should use "ZegoPublishChannelMain".

  • ZegoDataRecordConfig specify the recording config. You can set the file path and recording type ZegoDataRecordType by this config.

If you want to record audio and video, you should designate it as "ZegoDataRecordTypeDefault" or "ZegoDataRecordTypeAudioAndVideo", if you want to record only audio, choose "ZegoDataRecordTypeOnlyAudio", and if you want to record only audio, then choose "ZegoDataRecordTypeOnlyVideo".

  • In the configuration of the specified recording ZegoDataRecordConfig, the suffix of the file path must 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.
// Interface calls such as login to the room, start streaming, start preview, etc.
...

// The example here looks for the Document path
NSArray *docsPathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docsPath = [docsPathArray objectAtIndex:0];

// Create recording configuration
ZegoDataRecordConfig *config = [[ZegoDataRecordConfig alloc] init];

// Set the recording file path, specify the mp4 format
config.filePath = [docsPath stringByAppendingPathComponent:@"ZGRecordCapture.mp4"];

// Set the specified recording audio and video
config.recordType = ZegoDataRecordTypeAudioAndVideo;

// Start recording, use the main channel to record
[[ZegoExpressEngine sharedEngine] startRecordingCapturedData:config channel:ZegoPublishChannelMain];

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.

[[ZegoExpressEngine sharedEngine] stopRecordingCapturedData:ZegoPublishChannelMain];

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.

FAQ

  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 starting 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 the 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