In the online education scenario, this solution can compose and record the audios/videos of the teacher and students during class and add other materials and AI analysis capability to restore the in-person class experience. It can also add other business features to enrich the video playback effect.
During live streaming, this solution can use the stream mix recording method to mix multiple streams and relay them for audit, thereby reducing the audit costs. It can also store the recording files according to applicable regulations to meet regulatory requirements.
In scenarios such as online account opening and financial audiovisual recording, this solution can record all transaction processes from a global perspective and archive the recording files to meet subsequent service or regulatory requirements.
In customer service and complaint handling scenarios, this solution can record the service process and complaint content in real time, making it easier to optimize the service quality, check the reasonableness of complaints, and improve the efficiency of complaint handling.
This document describes how to use API Gateway and SCF to mix record the anchor audio/video streams in a TRTC room and upload the recording file to COS for storage. This solution provides out-of-the-box, flexible, convenient, and programmable live recording capabilities. SCF offers 512 MB of memory by default for recording file storage. If you need more storage space, you can choose to use the mount capability of CFS. The workflow is as shown below:
The recording rules are as follows:
IsReserve
is true, after the user exits the room, the user's stream will still be in the stream mix task, and the last frame of video image and mute will be used to complement the stream. If IsReserve
is false, after the user exits the room, the user's stream will be deleted from the stream mix task. If a new user enters the room later, the new user's stream will be added to the stream mix.The parameters for calling APIs are as follows:
Parameter | Type | Required | Description |
---|---|---|---|
SdkAppId | Int | Yes | Application ID, which is used to distinguish different TRTC applications. |
RoomId | Int | Yes | Room ID in integer type, which is used to uniquely identify a room in a TRTC application. |
StrRoomId | String | No | Room ID in string type. Either RoomId or StrRoomId must be configured. If both are configured, RoomId will be used. |
UserId | String | Yes | Recorded user ID, which is used to uniquely identify a user in a TRTC application. |
UserSig | String | Yes | Recorded user signature, which is used to authenticate the user login. |
CosConfig | cosConfig | Yes | COS storage configuration for recording file storage. |
Callback | String | No | Callback address after recording. The POST method is used for callback. |
Mode | String | No | |
IsReserve | Boolean | No | true . |
// The parameters involved in CosConfig
are as follows:
Parameter | Type | Required | Description |
---|---|---|---|
SecretId | String | No | SecretId of Tencent Cloud account. For more information, please see Root Account Access Key Management. |
SecretKey | String | No | SecretKey of Tencent Cloud account. For more information, please see Root Account Access Key Management. |
Region | String | Yes | COS region, such as ap-guangzhou . |
Bucket | String | Yes | Bucket name, such as susu-123456789 . |
Path | String | Yes | Path in the bucket. For example, for /test , the root directory is / . |
Note:
UserId
is the specified user ID. Idempotency is not guaranteed for multiple requests to API Gateway.- If
SecretId
andSecretKey
are not configured inCosConfig
, the function will use the permission of the execution roleSCF_ExecuteRole
when accessing COS.
Trigger conditions for stopping recording:
RoomId
, you need to call the RemoveUser API.StrRoomId
, you need to call the RemoveUserByStrRoomId API.After recording is stopped, the data returned by the function is as follows:
Parameter | Type | Required | Description |
---|---|---|---|
SdkAppId | String | Yes | Application ID. |
RoomId | String | Yes | Room ID in integer type. |
UserId | String | Yes | Recorded user ID. |
StrRoomId | String | Yes | Room ID in string type. |
Files | Array | Yes | [{},{},{},{}] |
Note:If callback is configured, after the stop, SCF will pass the returned data to the callback address in POST method.
Each item in the Files
array is a JSON object as follows:
Parameter | Type | Required | Description |
---|---|---|---|
UserId | String | Yes | Recorded user ID. |
RecordFile | String | Yes | URL of the recording file uploaded to COS. |
Status | Int | Yes | |
Message | String | Yes | Execution result of the recording task, such as recording failed, transcoding failed, and write to COS failed. |
Note:To enable CFS, you need to set the environment variable
CFS_PATH
to a local directory, such as/mnt/audio/
.
roomId
is the room ID of the created TRTC application, and userId
is the ID of another random user (which must be unique). Below is the sample code:{
"SdkAppId": 1400000000,
"RoomId": 43474,
"UserId": "user_55952145",
"Mode":"12",
"UserSig": "eJwtzNEKgkAUBNB-2efQ3e3eUqG3tMCKJJEIIxxxxxxxxxxxxxxxhvmweLWzGlUxj0mLs1GXKVf3mgrq*GFUdUR0UQrAYWDyW6Y15cwTwDm4UkxF36iXpkq1joiSc9xxxxxxxxxxxxx-S*CZeOk9sHfnEhCwlUW*fE4oWusw3dULlJ7HoSJ2e6d9fM8Y98fxUAzWA__",
"CosConfig": {
"Region": "ap-shanghai",
"Bucket": "test-123456789",
"Path": "/trtc"
},
"IsReserve":false,
"Callback":"https:xxxxxxxx.com/post/xxx"
}
See the figure below:RequestId
of this function will be returned through x-scf-reqid
in the HTTP header as shown below:
Was this page helpful?