Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

Composite recording

Agora Cloud Recording supports three recording modes:

  • Individual recording
  • Composite recording
  • Web page recording

In composite recording mode, the audio and video of multiple user IDs in a channel are recorded in a single file.

For example, if a channel has two users, and you choose to record both audio and video, Agora Cloud Recording generates files as shown in the following diagram:

The recording service generates one M3U8 file and multiple TS files. If you set avFileType as ["hls","mp4"] when calling the start method, the recording service also generates MP4 files, which include the audio and video of all users in the channel.

This guide explains how to implement composite recording using Cloud Recording REST API.

Implementation

Get a resource ID

Before recording, call the acquire method to apply for a resource ID.

An HTTP request example of acquire

  • Request URL:

_1
https://api.agora.io/v1/apps/<yourappid>/cloud_recording/acquire

  • Content-type: application/json;charset=utf-8
  • Authorization: Basic authorization. For more information, see Authenticate REST calls.
  • Request body:

_8
{
_8
"cname": "httpClient463224",
_8
"uid": "527841",
_8
"clientRequest": {
_8
"resourceExpiredHour": 24,
_8
"scene": 0
_8
}
_8
}

Start recording

To enable composite recording mode, set mode to mix when calling start. Use recordingConfig to configure composite recording, and use storageConfig to configure your third-party cloud storage.

You cannot switch to a different recording mode once you start recording.

In composite recording mode, you can configure the following parameters in clientRequest:

ParameterDescriptionNote
tokenThe dynamic key used for the channel to record.Required if the channel uses a token
recordingConfigConfigures stream subscription, transcoding, and the profile of the output audio and video.Required
recordingFileConfigConfigures the recorded files.Optional
storageConfigConfigures the third-party cloud storage.Required

An HTTP request example of start

  • Request URL:

_1
https://api.agora.io/v1/apps/<yourappid>/cloud_recording/resourceid/<resourceid>/mode/mix/start


_42
{
_42
"uid": "527841",
_42
"cname": "httpClient463224",
_42
"clientRequest": {
_42
"token": "<token if any>",
_42
"recordingConfig": {
_42
"maxIdleTime": 30,
_42
"streamTypes": 2,
_42
"audioProfile": 1,
_42
"channelType": 0,
_42
"videoStreamType": 0,
_42
"transcodingConfig": {
_42
"height": 640,
_42
"width": 360,
_42
"bitrate": 500,
_42
"fps": 15,
_42
"mixedVideoLayout": 1,
_42
"backgroundColor": "#FF0000"
_42
},
_42
"subscribeVideoUids": [
_42
"123",
_42
"456"
_42
],
_42
"subscribeAudioUids": [
_42
"123",
_42
"456"
_42
],
_42
"subscribeUidGroup": 0
_42
},
_42
"storageConfig": {
_42
"accessKey": "xxxxxxf",
_42
"region": 3,
_42
"bucket": "xxxxx",
_42
"secretKey": "xxxxx",
_42
"vendor": 2,
_42
"fileNamePrefix": [
_42
"directory1",
_42
"directory2"
_42
]
_42
}
_42
}
_42
}

Stop recording

When a recording finishes, call stop to leave the channel and stop recording. To use Agora Cloud Recording again, you need to call the acquire method for a new resource ID.

An HTTP request example of stop

  • The request URL is:

_1
http://api.agora.io/v1/apps/<yourappid>/cloud_recording/resourceid/<resourceid>/sid/<sid>/mode/mix/stop


_5
{
_5
"cname": "httpClient463224",
_5
"uid": "527841",
_5
"clientRequest": {}
_5
}

Recorded files

The content of the recorded files varies according to the setting of streamTypes. See the table below:

Recorded contentSettingsRecorded files
Audio onlySet streamTypes as 0One M3U8 file, several TS files, and one or more MP4 files if you set avFileType as ["hls","mp4"]. The TS files and MP4 files store the audio.
Video onlySet streamTypes as 1One M3U8 file, several TS files, and one or more MP4 files if you set avFileType as ["hls","mp4"]. The TS files and MP4 files store the video.
Audio and videoSet streamTypes as 2 (default)One M3U8 file, several TS files, and one or more MP4 files if you set avFileType as ["hls","mp4"]. The TS files and MP4 files store the audio and video.

For detailed information about the naming conventions of the recorded files, see Manage Recorded Files.

Considerations

A Web client and a Native client have different display strategies when they stop publishing streams or leave the channel. See the table below for details.

Type of the publisherThe client unpublishes the local video stream (unpublish)The client disables the video track (muteVideo/setEnabled)The client leaves the channel
Native clientDisplays the last frame of the video within 3.5 seconds.Displays the preset background image of the canvas or the user region after 3.5 seconds, see Set the background image; If a background image is not set, the last frame is displayed.Displays the last frame of the video within 3.5 seconds.Displays the preset background image of the canvas or the user region after 3.5 seconds, see Set the background image; If a background image is not set, the last frame is displayed.Displays the background color of the canvas (backgroundColor).
Web clientFor the Web SDK 4.x and later, the last frame of the video is displayed within 3.5 seconds.The preset background image of the canvas or the user region is displayed after 3.5 seconds, see Set the background image. If a background image is not set, the last frame is displayed.For the Web SDK 4.x and later, the last frame of the video is displayed within 3.5 seconds.The preset background image of the canvas or the user region is displayed after 3.5 seconds, Set the background image. If a background image is not set, the last frame is displayed.Displays the background color of the canvas (backgroundColor).
vundefined