On-Cloud Recording and Playback

Last updated: 2021-09-06 10:34:08

    Use Cases

    In application scenarios such as remote education, live show streaming, video conferencing, remote loss assessment, financial audiovisual recording, and online healthcare, it is often necessary to record an entire video call or live streaming session and save the recording files for purposes such as evidence gathering, quality control, auditing, archiving, and playback.

    With TRTC’s on-cloud recording feature, you can record the audio/video streams of each user in a room into a separate file.

    You can also mix the audio/video streams in a room into one stream through On-Cloud MixTranscoding and then record the mixed stream into a file.

    Console Guide

    Enabling the recording feature

    1. Log in to the TRTC console and click Application Management on the left sidebar.
    2. Find your application and click Function Configuration on the right. If you haven’t created an application yet, click Create Application, enter an application name, and click Confirm to create one.
    3. Click next to Enable On-Cloud Recording. The configuration page for on-cloud recording appears.

    Selecting the recording mode

    TRTC supports recording in two modes: Global Auto-Recording and Specified User Recording.

    • Global Auto-Recording
      The upstream audio/video streams of all users in all TRTC rooms are automatically recorded. The recording starts and stops automatically. Since no human intervention is needed, this mode is easier and simpler. For detailed instructions, see Scheme 1: Global Auto-Recording.

    • Specified User Recording
      You can specify users whose streams you want to record. This is achieved using either the client-side SDK API or server-side RESTful API for on-cloud recording and therefore requires additional development efforts. For detailed instructions, see Scheme 2: Specified User Recording (SDK API) and Scheme 3. Specified User Recording (RESTful API).

    Choosing a format for recording files

    TRTC can record streams in four formats, namely HLS, MP4, FLV, and AAC, whose differences and application scenarios are listed in the table below. Choose one that fits your needs.

    ItemDescription
    File format Four file formats are supported:
    • HLS: files in this format can be played back on most browsers and are suitable for video replay scenarios. When this format is selected, recording can resume from breakpoints, and no upper limit is set on the recording length of a file.
    • FLV: files in this format cannot be played back on browsers, but the format is simple and fault tolerant. You may consider using this format if you do not need to store recording files in VOD. Just download the files immediately after recording and delete the original files.
    • MP4: files in this format can be played back on browsers, but the format is not fault tolerant. Any packet loss during a video call may affect the playback quality of the recording file.
    • AAC: select this format if you want to record audio only.
    Maximum file length (min)
    • You can set a maximum length for recording files based on your needs. The system will automatically segment files that exceed the limit. The valid value range is 5-120 (minutes).
    • When **HLS** is selected for **File Type**, no limit is set on the length of recording files, and this parameter becomes invalid.
    File retention duration (day) You can set for how many days you want VOD to save your recording files based on your needs. The valid value range is 0-1080 (days). Files that expire will be deleted and cannot be retrieved. 0 means saving the files indefinitely.
    Resumption timeout (sec)
  • By default, if a call/live streaming session is interrupted due to network jitter or other reasons, the stream of the call will be recorded into multiple files.
  • You can set this parameter if you want to generate only one playback link for each call/live streaming session. If recording is cut off for a period shorter than the specified time, only one file will be generated for a call/live streaming session, but you have to wait till the timeout period elapses to get the file.
  • The valid value range of this parameter is 1-1800 (seconds). 0 means disabling the breakpoint resume function.
  • Note:

    HLS supports a maximum resumption timeout threshold of 30 minutes, making it possible to generate only one playback link for each lecture. What’s more, files in the HLS format can be played back on most browsers, making the format ideal for video playback in online education scenarios.

    Setting the path to save recording files

    In TRTC, recording files are stored in Tencent Cloud’s VOD platform by default. If more than one of your businesses share a Tencent Cloud VOD account, you may want to separate their recording files, which you can achieve through VOD’s subapplication feature.

    • What are VOD primary applications and subapplications?
      Primary applications and subapplications offer a way to separate your resources in VOD. A primary application is essentially your VOD account. Multiple subapplications can be created under a primary application, each of which functions as a a sub-account of the VOD account. The resources of subapplications are managed separately and assigned dedicated storage space.

    • How do I enable the subapplication feature in VOD?
      You can follow the steps in Subapplication System to create subapplications in the VOD console.

    Configuring the recording callback

    To receive notifications about the generation of new recording files in real time, enter in Recording Callback Address an HTTP or HTTPS address on your server for the callbacks of recording files. When a new recording file is generated, Tencent Cloud will send a notification to your server via this address.

    For more details on receiving callbacks of recording files and how to interpret the callbacks received, please see Receiving recording files below.

    Recording Schemes

    TRTC offers three on-cloud recording schemes, namely global auto-recording, specified user recording (SDK API), and specified user recording (RESTful API). We will explain the following for each of the scheme.

    • How do I select the scheme in the console?
    • How do I start a recording task?
    • How do I end a recording task?
    • How do I mix multiple image streams in a room into one stream?
    • How is a recording file named?
    • What platforms support the scheme?

    Scheme 1: Global Auto-Recording

    • Selecting the scheme in the console
      To use this recording scheme, set On-Cloud Recording Mode to Global Auto-Recording in the console.

    • Start a recording task
      The audio/video streams of each user in a TRTC room are recorded automatically, with no need for human intervention.

    • Ending a recording task
      A task stops automatically when an anchor stops sending audio/video data. However, if you have set the Resumption Timeout parameter when choosing the format for recording files, you will not receive the recording file until the timeout threshold is reached.

    • Mixing streams
      There are two on-cloud stream mixing options in the global auto-recording mode: via the server-side RESTful API and client-side SDK API. Choose one and stick to it.

    • Naming of recording files

      • If an anchor has set userDefineRecordId during room entry, recording files will be named userDefineRecordId_streamType__start time_end time (streamType has two valid values: main, which indicates the primary stream, and aux, which indicates the substream.)
      • If an anchor has set streamId, but not userDefineRecordId during room entry, recording files will be named streamId_start time_end time.
      • If an anchor has set neither userDefineRecordId nor streamId during room entry, recording files will be named sdkappid_roomid_userid_streamType_start time_end time (streamType has two valid values: main, which indicates the primary stream, and aux, which indicates the substream.)
    • Supported platforms
      Recording operations are initiated by your server and are not affected by the platform on which the SDK runs.

    Scheme 2: User Specified Recording (SDK API)

    You can enable on-cloud stream mixing, on-cloud recording and relayed live streaming by calling some APIs of the TRTC SDK.

    On-Cloud Capability Enabling Disabling
    On-cloud recording Specify the userDefineRecordId field in TRTCParams during room entry. The recording stops automatically when the anchor exits the room.
    On-cloud stream mixing Call the SDK API setMixTranscodingConfig() to start on-cloud stream mixing. The mixing stops automatically when the anchor who starts it exits the room. The anchor can also stop it manually by calling setMixTranscodingConfig(), with the parameter set to null/nil.
    Relayed live streaming Specify the streamId field in TRTCParams during room entry. The relaying stops automatically when the anchor exits the room.

    • Selecting the scheme in the console
      To use this recording scheme, set On-Cloud Recording Mode to Specified User Recording in the console.

    • Starting a recording task
      If an anchor has set userDefineRecordId in the room entry parameter TRTCParams during room entry, the audio/video data sent by the anchor will be recorded on the cloud. The streams of anchors who have not set the parameter are not recorded.

      // Sample code: select the user rexchang for specified user recording, the ID of the recording file being `1001_rexchang`
      TRTCCloud *trtcCloud = [TRTCCloud sharedInstance];
      TRTCParams *param = [[TRTCParams alloc] init];
      param.sdkAppId = 1400000123; // SDKAppID in TRTC, which is generated after the creation of an application
      param.roomId = 1001; // Room ID
      param.userId = @"rexchang"; // User ID
      param.userSig = @"xxxxxxxx"; // Login signature
      params.role = TRTCRoleAnchor; // Role: anchor
      param.userDefineRecordId = @"1001_rexchang"; // Recording ID. Specify the user whose streams are to be recorded
      [trtcCloud enterRoom:params appScene:TRTCAppSceneLIVE]; // Please use the `LIVE` mode
    • Ending a recording task
      The task stops automatically after the anchor who has set userDefineRecordId during room entry stops sending audio/video. However, if you have set the Resumption Timeout parameter when choosing the format for recording files, you will not receive the recording file until the timeout threshold is reached.

    • Mixing streams
      You can call the SDK API setMixTranscodingConfig() to mix the audio/video streams of other users in a room into the current user's audio/video streams. For details, see On-cloud MixTranscoding.

      Note:

      Make sure that the setMixTranscodingConfig API is called by just one anchor (preferably the anchor who created the room) in a TRTC room. Calling of the API by multiple anchors may cause confusion.

    • Naming of recording file
      Recording files are named userDefineRecordId_start time_end time.

    • Supported platforms
      Recording tasks can be initiated on iOS, Android, Windows, macOS, and Electron, but not on browsers currently.

    Scheme 3: Specified User Recording (RESTful API)

    TRTC's server provides a pair of RESTful APIs (StartMCUMixTranscode and StopMCUMixTranscode) for the implementation of on-cloud stream mixing, on-cloud recording, and relayed live streaming.

    On-Cloud Capability Enabling Disabling
    On-cloud recording Specify OutputParams.RecordId when calling StartMCUMixTranscode to enable recording. The recording stops automatically. It can also be manually stopped via the calling of StopMCUMixTranscode.
    On-cloud stream mixing Specify LayoutParams when calling StartMCUMixTranscode to select a layout template and set other layout parameters. The recording stops automatically when the last user exits the room. It can also be manually stopped via the calling of StopMCUMixTranscode.
    Relayed live streaming Specify OutputParams.StreamId when calling StartMCUMixTranscode. The relaying stops automatically. It can also be manually stopped via the calling of StopMCUMixTranscode.
    Note:

    The two RESTful APIs work via the core stream mixing MCU of TRTC and send the streams mixed to the recording system and live streaming CDNs, hence the name Start/StopMCUMixTranscode. In addition to stream mixing, the APIs can be used to enable on-cloud recording and CDN relayed live streaming as well.

    • Selecting the scheme in the console
      To use this recording scheme, set On-Cloud Recording Mode to Specified User Recording in the console.

    • Starting a recording task
      Call StartMCUMixTranscode from your server, with OutputParams.RecordId set to enable stream mixing and recording.

      // Sample code: start an on-cloud stream mixing and on-cloud recording task through the RESTful API
      https://trtc.tencentcloudapi.com/?Action=StartMCUMixTranscode
      &SdkAppId=1400000123
      &RoomId=1001
      &OutputParams.RecordId=1400000123_room1001
      &OutputParams.RecordAudioOnly=0
      &EncodeParams.VideoWidth=1280
      &EncodeParams.VideoHeight=720
      &EncodeParams.VideoBitrate=1560
      &EncodeParams.VideoFramerate=15
      &EncodeParams.VideoGop=3
      &EncodeParams.BackgroundColor=0
      &EncodeParams.AudioSampleRate=48000
      &EncodeParams.AudioBitrate=64
      &EncodeParams.AudioChannels=2
      &LayoutParams.Template=1
      &<Common request parameters>
      
    Note:

    • The RESTful API works only when at least one user has entered the room (enterRoom).
    • The RESTful API cannot be used to record single streams. If you want to record single streams, choose Scheme 1 or Scheme 2.
    • Ending a recording task
      Stream mixing and recording tasks stop automatically. You can also stop them manually by calling StopMCUMixTranscode.

    • Mixing streams
      Set LayoutParams when calling StartMCUMixTranscode to enable on-cloud stream mixing. The API can be called multiple times during live streaming, meaning that you can modify the LayoutParams parameter to change the layout of video images, but make sure that you use the same OutputParams.RecordId and OutputParams.StreamId for each calling; otherwise the recording will be interrupted and multiple recording files will be generated.

    Note:

    For more details on on-cloud stream mixing, see On-Cloud MixTranscoding.

    • Naming of recording files
      Recording files are named OutputParams.RecordId_start time_ end time, in which OutputParams.RecordId is set when StartMCUMixTranscode is called.

    • Supported platforms
      Recording operations are initiated by your server and are not affected by the platform on which the SDK runs.

    Searching for Recording Files

    When recording is enabled, files recorded in TRTC can be found in Tencent Cloud’s VOD platform. You can search for files in the VOD console or use a RESTful API on your server for scheduled filtering.

    Method 1: searching for files in the VOD console

    1. Log in to the VOD console and click Media Assets on the left sidebar.
    2. Click Search by prefix above the list, select Search by prefix, enter a keyword, e.g. 1400000123_1001_rexchang_main in the search box, and click to show the files whose names match.
    3. You can filter files by creation time.

    Method 2: searching for files through a RESTful API

    VOD provides a series of RESTful APIs for the management of audio/video files. You can use the RESTful API SearchMedia to query files in VOD. You can also use the request parameter Text for fuzzy searches or the StreamId parameter for exact searches.
    Sample RESTful request:

    https://vod.tencentcloudapi.com/?Action=SearchMedia
    &StreamId=stream1001
    &Sort.Field=CreateTime
    &Sort.Order=Desc
    &<Common request parameters>
    

    Receive Recording Files

    Besides searching for recording files, you can have Tencent Cloud push notifications about the generation of new recording files to your server by configuring a callback address.
    Upon the exit of the last user from a room, Tencent Cloud will stop recording and save the recording file in VOD. This normally takes about 30-120 seconds. If you have set a resumption timeout threshold, for example, 300 seconds, then the process will take 300 seconds longer. After saving the file, Tencent Cloud will send a notification to your server via the specified (HTTP/HTTPS) callback address.

    Tencent Cloud sends information about both the recording itself and recording-related events to your server via the specified callback address. Below is an example of a callback message:

    The fields in the table below can help you determine which call/live streaming session a callback is about.

    No.FieldDescription
    event_type Message type. `100` indicates that a recording file is generated.
    stream_id Stream ID for CDN live streaming, which you can set by specifying the streamId field in `TRTCParams` during room entry (recommended), or when calling the `startPublishing` API of `TRTCCloud`.
    stream_param.userid Base64-encoded user ID
    stream_param.userdefinerecordid Custom field. You can set this field by specifying the userDefineRecordId field in `TRTCParams`.
    video_url Playback address of the recording file, which can be used for VOD playback.

    Deleting Recording Files

    VOD provides a series of RESTful APIs for the management of audio/video files. You can use the DeleteMedia API to delete a file.
    Sample RESTful request:

    https://vod.tencentcloudapi.com/?Action=DeleteMedia
    &FileId=52858907988664150587
    &<Common request parameters>
    

    Replaying Recording Files

    In application scenarios such as online education, to make the best of teaching resources, it is often necessary to replay recording files multiple times.

    Select the file format (HLS)

    Select HLS as the file format when selecting the file format.
    HLS supports a maximum timeout threshold of 30 minutes for breakpoint resumption, making it possible to generate only one playback link for each live streaming session/lecture. What’s more, files in HLS format can be played back on most browsers, making it an ideal format for replay.

    Get the playback address (video_url)

    After receiving a recording file callback, you can get the playback address of the file by looking for the video_url field in the callback message.

    Integrate the VOD player

    Integrate the VOD player designed for your platform. For detailed instructions, see the documents below.

    Note:

    We recommend the Professional TRTC SDK, which integrates features including superplayer (Player+) and Mobile Live Video Broadcasting (MLVB). This integrated edition adds less to the size of the application package than two independent SDKs do because many underlying modules are shared among the services. It is also free of the duplicate symbol issue.

    Billing

    The costs of on-cloud recording and playback are listed below. A basic service fee is charged for recording. Other fees are charged based on your usage.

    Note:

    The prices used in the examples in this document are for reference only. In case of any inconsistencies, the prices specified in On-Cloud Recording Billing Overview, Live Broadcasting Pricing and VOD Pricing shall prevail.

    Recording fee: the computing cost of transcoding or remuxing

    As server computing resources are needed to transcode or remux audio/video streams during recording, you are charged a recording fee based on the computing resources used for recording.

    Note:

    • For Tencent Cloud accounts that create their first applications on or after July 1, 2020, the prices listed in On-Cloud Recording Billing Overview shall apply.
    • Tencent Cloud accounts that created applications before July 1, 2020 will continue to be charged the CSS Recording fee for the use of the recording service, whether the service is used by applications created before or after July 1, 2020.

    The CSS Recording fee is calculated based on the peak number of concurrent recording channels. The higher the number, the higher the fee. For details, see CSS > CSS Recording.

    Assume that you have 1,000 anchors, and during peak times, it’s necessary to record the audio/video streams of 500 of them at the same time. If the service is priced 5.2941 USD per channel per month, then you will be charged 500 channels x 5.2941 USD/channel/month = 2,647.05 USD/month.
    If you select two file formats, both the recording and storage fees will double. If you select three, they will triple. To reduce cost, you are not advised to select more than one file format unless necessary.

    Storage fee: charged for storing files with Tencent Cloud
    As storage requires disk resources, if you store recording files with Tencent Cloud, you will be charged based on the disk resources used. The longer you store a file, the higher the cost. To reduce cost, you are advised to keep the storage duration short or store recording files on your own server if possible. Storage fees are postpaid on a daily basis.

    For example, if you set the anchor bitrate (videoBitrate) to 1,000 Kbps when calling setVideoEncodrParam() and select a file format to record an anchor's live streams for an hour, the size of the recording file generated will be approximately (1,000/8) KBps x 3,600s = 450,000 KB = 0.45 GB. If you store the file with Tencent Cloud, the storage fee per day will be 0.45 GB x 0.0009 USD/GB/day=0.000405 USD.

    Playback fee: charged for playing back a file

    As playback consumes CDN traffic, if you play back a recording file, you will be subject to VOD’s billing standards. By default, you are charged a video acceleration fee based on the traffic consumed by playback. The larger audience you serve, the higher the cost. Playback fees are postpaid on a daily basis.

    Assume that you recorded a 1 GB file on the cloud and played it back to 1,000 users from beginning to end. The traffic consumed amounts to 1 TB, and according to VOD’s tiered pricing system, you will be charged 1,000 x 1 GB x 0.0794 USD/GB = 79.4 USD.
    If you download files from Tencent Cloud to your server, a relatively small amount of traffic will be consumed too, which is billed on a monthly basis.

    Transcoding fee: charged for using the stream mixing service

    As stream mixing involves encoding and decoding, you will incur an additional transcoding fee if you enable stream mixing. The fee varies with the resolution used and the duration of transcoded streams. The higher resolution used for anchors, and the longer co-anchoring (the most common application scenario for stream mixing) lasts, the higher the cost. For more information, see CSS Transcoding.

    Assume that you used setVideoEncodrParam() to set the bitrate (videoBitrate) for anchors to 1,500 Kbps and resolution to 720p, and an anchor co-anchored with a viewer for 1 hour, during which On-Cloud MixTranscoding was enabled. The transcoding fee incurred would be 0.0057 USD/min x 60 min=0.342 USD.