Individual recording

Updated

How to record audio and video in individual recording mode using command line.

The On-Premise Recording SDK supports two recording modes:

  • Individual recording mode: This is the default recording mode. The SDK generates one audio and/or video file for each UID.
  • Composite recording mode: Generates a single mixed audio and video file for all UIDs in a channel, or mixes the audio of all UIDs in the channel into an audio file and the video of all UIDs into a video file.

See Differences between individual recording mode and composite recording mode to decide which mode you should use.

Prerequisites

Before continuing, follow the Quickstart guide to integrate the Recording SDK and implement the basic recording functionality.

Implement individual recording

The implementation of individual recording is largely similar to the steps in the Quickstart guide. The main differences are in the configuration parameters and the APIs used.

Refer to the following call sequence diagram to understand the recording workflow.

Sequence diagram

To implement individual recording in your app, follow these steps:

  1. Initialize the recorder with enableMix set to false to enable individual recording mode.
  2. Subscribe to the audio and video streams of the users you want to record.
  3. Join the channel using joinChannel.
  4. Wait for the onUserJoined callback to get the uid of each remote user.
  5. Configure recording for the specific uid:
  6. Start and stop recording for each user:

Refer to the following code to implement these steps:

// Initialize the recorder in individual recording mode
recorder->initialize(service, false);

// Subscribe to all audio and video streams
recorder->subscribeAllAudio();
recorder->subscribeAllVideo(options);

// Join the channel
recorder->joinChannel(config.token.c_str(), config.ChannelName.c_str(), config.UserId.c_str());

// After receiving the onUserJoined callback, configure recording for the given uid
agora::media::MediaRecorderConfiguration config;
config.fps = config_.video.fps;
config.width = config_.video.width;
config.height = config_.video.height;
config.channel_num = config_.audio.numOfChannels;
config.sample_rate = config_.audio.sampleRate;

// Generate a unique file name using uid and timestamp
std::string curTime = getCurrentTimeAsString();
std::string storagePath = config_.recorderPath + std::string(uid) + "_" + curTime + ".mp4";
config.storagePath = storagePath.c_str();
config.streamType = static_cast<agora::media::MediaRecorderStreamType>(config_.recorderStreamType);
config.maxDurationMs = config_.maxDuration * 1000;

// Apply configuration for the specific user
recorder_->setRecorderConfigByUid(config, uid);

// Apply watermarks (optional)
recorder_->enableAndUpdateVideoWatermarksByUid(watermarks, config_.waterMarks.size(), uid);

// Start recording for the user
recorder_->startSingleRecordingByUid(uid);

// ...

// Stop recording for the user
recorder_->stopSingleRecordingByUid(uid);

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

Considerations

The individual recording mode supports a specific set of APIs. Calling unsupported methods in the wrong mode has no effect. When using the individual recording mode, the following methods do not work: