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:
- Initialize the recorder with
enableMixset tofalseto enable individual recording mode. - Subscribe to the audio and video streams of the users you want to record.
- Join the channel using
joinChannel. - Wait for the
onUserJoinedcallback to get theuidof each remote user. - Configure recording for the specific
uid:- Use
setRecorderConfigByUidto define video and audio settings, storage path, and maximum duration. - Optionally use
enableAndUpdateVideoWatermarksByUidto apply watermarks.
- Use
- Start and stop recording for each user:
- Call
startSingleRecordingByUidto start. - Call
stopSingleRecordingByUidto stop.
- Call
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:
