All Products
Search
Document Center

ApsaraVideo Live:Live stream recording

Last Updated:Apr 08, 2025

ApsaraVideo Live recording can record the current live stream in real-time and enable historical playback. This topic describes the ApsaraVideo Live recording feature.

Function introduction

ApsaraVideo Live plays data from the ingest source in the form of real-time streams. If you want to watch the content again after the live stream ends, you must use the live stream recording feature.

Live stream recording is the process of recording streaming data received by the live center and saving it to your specified storage location. Currently, two methods are provided for live stream recording storage: Recording Stored In VOD and Recording Stored In OSS.

How live stream recording works

The process of live stream recording is to pull the live stream that you push, encapsulate the audio and video into individual media segments (with TS as the container format), and then store them. The live stream recording feature complies with the following principles:

  • Live stream recording only modifies the container format of audio and video (converting RTMP/FLV to TS) and never modifies the audio and video content (i.e., the content at the coding layer). For example, if the live stream you push has a distorted screen, the recorded content will also have a distorted screen.

  • Live stream recording has permission to write recording files to the user's storage address, but it does not have permission to modify/delete task files (including the recorded files that have been written) in the user's storage address. The recording files in the user's storage address are completely managed by you.

Important

Using the live stream recording feature will incur recording service fees. The default recording file format is TS/M3U8. If transcoding and container format conversion processing is required, recording container format conversion fees will be incurred. For billing rules, see Live Stream Recording Fees.

Conditions

Audio and video encoding formats

ApsaraVideo Live needs to segment live streams into TS files first. Therefore, the audio and video encoding formats of the live streams that you ingest must meet the requirements of the TS container format. Based on the FLV and ISO/IEC 13818-1 standards, the live stream recording feature currently supports the following encoding formats:

  • Video: H.264, HEVC, and MPEG-4

  • Audio: AAC and MP3

Note

If the live stream contains audio and video encoded in formats other than those mentioned above, the following issues may occur during live stream recording: failure to generate recording files, black screen recordings, recordings without sound, and other unforeseen abnormal situations.

Abnormal stream processing mechanism

  1. Standard stream (meets encoding requirements with stable frame rate/timestamp) ✅ 100% normal generation of recording files

  2. Minor abnormal stream (occasional frame rate fluctuation/timestamp jump) ✅ System automatically handles for compatibility

  3. Critical abnormal stream (long-term absence of video frames/disordered timestamps/missing keyframes) ❌ Recording success rate cannot be guaranteed

Feature comparison

You can store the recordings of a live stream in ApsaraVideo VOD or OSS. These two methods are suitable for different scenarios. You can choose a storage method based on your business requirements.

Storage method

Associated products and services

Supported recording methods

Container format

Scenarios

Record and store to VOD

Activate ApsaraVideo VOD

  • TS/M3U8 (default)

Tends to focus on post-production of recorded content, emphasizing post-processing such as video editing, playback, setting thumbnails for recorded videos, etc.

Recordings stored in OSS

Activate OSS

  • Automatic recording: Records content in a hierarchical manner by domain name, AppName, and StreamName.

  • On-demand recording: Configure a callback. The live streaming service starts recording after receiving a response indicating that recording is required.

  • Manual recording: By default, recording is disabled. You can manually record by calling the API.

  • TS/M3U8 (default)

  • MP4

  • FLV

  • CMAF

You want to focus on the management and storage of recordings.

Note
  • The same live stream Cannot Simultaneously be configured with two storage methods.

  • Live stream recording first segments the live stream into individual TS segments, and then combines them into recording files with the corresponding container format. Encapsulation into formats other than TS/M3U8 will incur container format conversion fees.

Automatic recording rules

You can specify a domain name, AppName, or StreamName to record all applications under a domain name, all live streams under an application, or precisely record a specific live stream. AppName and StreamName can be set to *, which represents all AppNames and all StreamNames.

You can configure multiple recording templates that specify recordings to store in OSS or VOD. However, if a live stream can match multiple recording templates at the same time, the recording templates take effect based on priority. The following describes the priority levels (a lower numeric value indicates a higher priority):

Priority

Domain name

AppName

StreamName

1

The Secret generated when the application is created.

The Secret generated when the application is created.

2

The Secret generated when the application is created.

*

3

*

*

A check mark (✓) indicates that the parameter has a value other than an asterisk (*) in the recording rule that you configure in the console or by calling an API operation. An asterisk (*) indicates that the parameter value is an asterisk (*).

Record and store to VOD

Prerequisites

If you use the recording storage to VOD method to configure the live stream recording feature, you need to activate ApsaraVideo VOD service, and configure Manage storage buckets.

Important
  • Recording files are stored in ApsaraVideo VOD, which incurs storage fees. For billing in VOD, see Basic service billing of video-on-demand.

  • When you enable the VOD bucket, make sure that the VOD bucket resides in the same region as the live center of the streaming domain.

  • You cannot configure the Live-to-VOD feature by using a Finance Cloud account.

Feature configuration

ApsaraVideo Live provides two methods to configure recording storage to VOD.

Note
  • After you configure the recording settings, you must re-ingest the stream for the configuration to take effect.

  • After a live stream is interrupted for 180 seconds, a recording file is generated for the live stream.

Method one: Console configuration

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Feature Management > Live Stream Recording to go to the Live Stream Recording page, and then select the Store To VOD Configuration tab.

  3. Select the streaming domain that you want to configure, and click Add.

  4. Configure the recording template.

    image

    The parameters and descriptions of the recording template are shown in the following table.

    Parameters

    Description

    AppName

    The application name of the video. The AppName you enter must be consistent with the AppName of the stream ingest to take effect. If you want to record at the domain name level, you can enter an asterisk (*).

    StreamName

    You can store the recording files of a specific live stream in ApsaraVideo VOD. You only need to enter the specified stream name. If you want to record all streams, which means recording all streams under the AppName, you can enter an asterisk (*).

    Note

    AppName and StreamName parameters support English letters, numbers, "-", and "_" characters, with a length limit of 255 characters.

    Storage Address

    Select a storage location.

    Recording Cycle

    Recording Cycle is the maximum duration after the current live stream is converted to a video-on-demand file. The range is 15 to 360 minutes, with a maximum recording time of 6 hours. If the recording exceeds 6 hours, the system generates a new file based on the recording naming convention. The default ts segment length is 30 seconds.

    Recording Transcoding Template

    Select a storage transcoding rule from the drop-down list. You can transcode the recorded videos in the video-on-demand service. You can transcode the videos to different formats or retain the original quality without transcoding.

    Recording and transcoding template operations, please see ApsaraVideo VOD transcoding configuration.

    Note

    The region of the transcoding template that you use in ApsaraVideo VOD must be the same as the region of your domain name. For example, if your domain name resides in the China (Shanghai) region, the transcoding template that you use in ApsaraVideo VOD must also reside in the China (Shanghai) region.

    Auto Merge Switch

    After you enable this feature, multiple recording cycle files can be automatically merged into one recording file and stored in VOD after the live stream recording ends.

    Note

    After you enable the auto merging of recording files of multiple cycles, the editing and production feature and the transcoding feature of ApsaraVideo VOD are required. For billing details, see Billing of editing and production and Billing of media transcoding.

    Custom Merge Transcoding Template

    Select a transcoding template from the drop-down list, which is obtained from the current video-on-demand system. The system performs transcoding on the automatically merged video in the video-on-demand service based on the settings of the transcoding template. For more information about operations on automatic merge transcoding templates, see Transcoding templates.

    Note

    The region of the transcoding template that you use in ApsaraVideo VOD must be the same as the region of your domain name. For example, if your domain name resides in the China (Shanghai) region, the transcoding template that you use in ApsaraVideo VOD must also reside in the China (Shanghai) region.

  5. Click OK.

Method 2: API configuration

Call the AddLiveRecordVodConfig - Add live stream recording to video-on-demand configuration interface to add configuration. The SDK call reference is as follows:

//Replace the content in angle brackets with actual values
DefaultProfile profile = DefaultProfile.getProfile("", "", "");
IAcsClient client = new DefaultAcsClient(profile);   
AddLiveRecordVodConfigRequest addLiveRecordVodConfigRequest=new AddLiveRecordVodConfigRequest();
addLiveRecordVodConfigRequest.setDomainName("");
addLiveRecordVodConfigRequest.setAppName("");
addLiveRecordVodConfigRequest.setStreamName("");
addLiveRecordVodConfigRequest.setVodTranscodeGroupId("VOD_NO_TRANSCODE");
//The address of the VOD bucket.
addLiveRecordVodConfigRequest.setStorageLocation("");
AddLiveRecordVodConfigResponse addLiveRecordVodConfigResponse = null;
try {
    addLiveRecordVodConfigResponse = client.getAcsResponse(addLiveRecordVodConfigRequest);
} catch (ClientException e) {
    e.printStackTrace();
}
 System.out.println(new Gson().toJson(addLiveRecordVodConfigResponse));
Note
  • The preceding sample code indicates that a recording storage configuration to VOD is set for the <DomainName> domain name, with AppName as <AppName> and StreamName as <StreamName>. The recorded content is not transcoded (VOD_NO_TRANSCODE) and is stored in the video-on-demand system bucket <StorageLocation>.

  • AppName and StreamName configuration details can be found in: Automatic recording rules.

Recording content transcoding

Recording is stored in VOD in m3u8 format. If you want to store it in other formats, you can configure the Recording Transcoding Template.

 addLiveRecordVodConfigRequest.setVodTranscodeGroupId("");
Note
  • The transcoding template needs to be configured in the video-on-demand system. For more information, see Transcoding template.

  • The Video-on-demand System Transcoding Template Group ID configured for the.

  • After you configure transcoding, the recording files are transcoded (the original files are retained) and the transcoded stream URLs are generated.

Merge recorded content

Recordings can be merged in the following two ways:

  1. If the same ingest endpoint is disconnected and then streaming is resumed within 180 Seconds, the recording content will be automatically merged into One recording file.

  2. Stream ingest duration exceeds the file merge after the Recording Cycle. After the stream ingest duration exceeds the Recording Cycle, a new recording file is generated (for example, if the recording cycle is set to 5 minutes and the stream ingest duration is 8 minutes, one stream ingest will produce two recording files).

    If you want to merge the recording files of different recording cycles, you can configure the merging settings.

    Important

    After you enable auto merge of recordings of multiple cycles, the editing and production feature and the transcoding feature of ApsaraVideo VOD will be used. For billing details, see Value-added service billing and Basic service billing.

    In the AddLiveRecordVodConfig - Add live stream recording to video-on-demand configuration interface, the example code for configuring recording file merging is as follows:

    addLiveRecordVodConfigRequest.setAutoCompose("ON");
    addLiveRecordVodConfigRequest.setComposeVodTranscodeGroupId("");
    Note
    • After merging, a new file is generated, and the original recording files are retained.

    • The transcoding template needs to be configured in the video-on-demand system. For more information about the operation, see Transcoding template.

    • The Video-on-demand System Transcoding Template Group ID configured for the.

    The following sample code provides an example on how to configure the recording cycle:

    //Unit: seconds. Valid values: 300 to 21600. Default value: 900.
    addLiveRecordVodConfigRequest.setCycleDuration(<300>);

Recording management

Currently, you can View the recordings stored in VOD through the ApsaraVideo Live console. You can manage the recordings through the ApsaraVideo VOD service. For more information, see media management in ApsaraVideo VOD.

View recording files stored in VOD in the ApsaraVideo Live console

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Feature Management > Live Stream Recording to go to the Live Stream Recording page, and then click the Recording Management File tab.

  3. Select the configured streaming domain.

  4. Click the Save To VOD tab.

    image

Recordings stored in OSS

Prerequisites

If you use the recording storage to OSS method to configure the live stream recording feature, you need to activate OSS service and create a bucket. For more information, see Configure OSS.

Important
  • Recording files stored in OSS will incur storage fees. For billing in OSS, see Storage fees.

  • The OSS bucket must reside in the same region as the live center of the domain to be configured.

Feature configuration

ApsaraVideo Live provides two methods to add configurations for storing recordings in OSS.

Note
  • After you configure the recording settings, you must ingest the stream again for the configuration to take effect.

  • Stream interruption that exceeds the stream splicing duration (default 180 seconds) generates a recording file.

Method one: Console configuration

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Feature Management > Live Stream Recording to go to the Live Stream Recording page, and then select the Store To OSS Configuration tab.

  3. Select the streaming domain that you want to configure, and click Add.

  4. Configure the recording template.

    image

    Table 1. Recording template parameters

    Parameters

    Description

    AppName

    The application name of the video. The AppName you enter must be consistent with the AppName in the ingest URL for the configuration to take effect. If you want to record at the domain name level, you can enter an asterisk (*).

    StreamName

    You can store the recordings of a specific live stream in OSS by specifying the stream name. If you want to record all streams, which means recording all streams under the AppName, you can enter an asterisk (*).

    Note
    • AppName and StreamName parameters support English letters, numbers, hyphens (-), and underscores (_). The length is limited to 255 characters.

    • The asterisk (*) can only be entered separately and cannot be used as a wildcard character in a string.

    Storage Location

    Select a storage location.

    Note

    Storage buckets are classified into two types:

    1. Standard bucket: Used for regular file storage

    2. Media Bucket: Dedicated to video transcoding processing. Files stored in this type of bucket automatically trigger MPS transcoding jobs.

    The current system does not identify or distinguish Bucket types. If you need to execute video transcoding, please record the media Bucket name you use to ensure the accurate storage location of the transcoded media files.

    Stream Splicing Duration

    If the stream interruption duration exceeds the specified duration, a new file is generated. The stream interruption duration ranges from 15 to 21600 seconds.

    Storage Format

    Supports four formats: FLV, M3U8, MP4, and CMAF.

    Note

    Select at least one storage format. You cannot select the CMAF and M3U8 formats at the same time.

    Storage Rules

    The default storage path is: record/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}.

    Sample command:

    AppName is liveApp****, StreamName is liveStream****, and the storage path for recording in m3u8 format is record/liveApp****/liveStream****/{EscapedStartTime}_{EscapedEndTime }.

    Single TS Duration

    The length of a single segment. Default value: 30 seconds. The length of a TS segment can range from 5 to 30 seconds.

    Recording Cycle

    Recording Cycle ranges from 15 minutes to 360 minutes, with a maximum recording duration of 6 hours. If the recording exceeds 6 hours, the system will generate a new file according to the recording naming convention.

    Note

    The recording cycle specifies the maximum length of a video-on-demand file that is converted from the current live stream.

  5. Configure recording transcoding stream. (Optional)

    Important

    When you use the live stream transcoding feature, you are charged based on the transcoding standard, resolution, and total length of transcoded streams. For more information about billing rules, see Live Stream Transcoding Fees.

    image

    Table 2. Recording transcoding stream parameters

    Parameters

    Description

    Recording Transcoding Stream

    Open the Record And Transcode Stream switch and configure the parameters.

    Storage Format

    Supports four formats: FLV, M3U8, MP4, and CMAF.

    Note

    Select at least one storage format. You cannot select the CMAF and M3U8 formats at the same time.

    Storage Rule

    The default storage path is: transcodeRecord/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}.

    Sample command:

    AppName is liveApp****, StreamName is liveStream****, Transcoding Template ID is lld, and the actual storage path when recording in m3u8 format is transcodeRecord/liveApp****/liveStream****_lld/{EscapedStartTime}_{EscapedEndTime}.

    Single TS Duration

    The length of a single segment. Default value: 30 seconds. The length of a TS segment can range from 5 to 30 seconds.

    Recording Cycle

    Recording Cycle ranges from 15 minutes to 360 minutes, with a maximum recording duration of 6 hours. If the recording exceeds 6 hours, the system generates a new file based on the recording naming convention.

    Note

    The recording cycle specifies the maximum length of a VOD file that is converted from the current live stream.

    Transcoding Template ID

    You can select specific transcoding templates (up to 10) or all transcoding templates.

    The AppName of the transcoding template must be consistent with the recording template to take effect. If there is no transcoding template, you need to add one first. For more information, see default transcoding.

  6. Click OK.

Method 2: API configuration

Call the AddLiveAppRecordConfig - Add recording configuration API to add a configuration. The SDK call reference is as follows:

        //Replace the content in angle brackets with actual values
        DefaultProfile profile = DefaultProfile.getProfile("", "", "");
        IAcsClient client = new DefaultAcsClient(profile);   
        AddLiveAppRecordConfigRequest addLiveAppRecordConfigRequest=new AddLiveAppRecordConfigRequest();
        addLiveAppRecordConfigRequest.setAppName("");
        addLiveAppRecordConfigRequest.setStreamName("");
        addLiveAppRecordConfigRequest.setDomainName("");
        addLiveAppRecordConfigRequest.setOssEndpoint("");
        addLiveAppRecordConfigRequest.setOssBucket("");
        List formatList=new ArrayList();
        AddLiveAppRecordConfigRequest.RecordFormat m3u8Format=new AddLiveAppRecordConfigRequest.RecordFormat();
        m3u8Format.setFormat("m3u8");
        //The naming format of a recording to store in OSS.
        m3u8Format.setOssObjectPrefix("");
        //The naming format of a segment.
        m3u8Format.setSliceOssObjectPrefix("");
        formatList.add(m3u8Format);
        addLiveAppRecordConfigRequest.setRecordFormats(formatList);
        AddLiveAppRecordConfigResponse addLiveAppRecordConfigResponse = null;
        try {
            addLiveAppRecordConfigResponse = client.getAcsResponse(addLiveAppRecordConfigRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(addLiveAppRecordConfigResponse));
Note
  • The above example code indicates that for the <DomainName> domain name, the configuration for recording storage to OSS is set with AppName as <AppName>, StreamName as <StreamName>, storage format as m3u8, and storage location in <OssBucket>.

  • can be viewed through the region to which belongs in OSS OSS regions and endpoints.

  • AppName and StreamName configuration details can be found in: Automatic recording rules.

Recording and transcoding stream

If you want to reduce the size of recording files when storing recorded content, you can achieve this by recording transcoded streams (adjusting video bitrate, increasing video compression rate, and reducing file size while ensuring video quality). The feature of storing recordings to OSS supports storing both transcoded and original streams simultaneously, and also supports storing only transcoded streams or original streams.

Important

When you use the live stream transcoding feature, you are charged based on the transcoding standard, resolution, and total length of transcoded streams. For more information about billing rules, see Live Stream Transcoding Fees.

Sample code for recording transcoded streams>>>

        //Replace the content in angle brackets with actual values        
        List transcodeFormatList=new ArrayList();
        AddLiveAppRecordConfigRequest.TranscodeRecordFormat m3u8TranscodeFormat=new AddLiveAppRecordConfigRequest.TranscodeRecordFormat();
        m3u8TranscodeFormat.setFormat("m3u8");
        //The naming format of a transcoded stream recording to store in OSS.
        m3u8TranscodeFormat.setOssObjectPrefix("");
        //The naming format of a segment in a transcoded stream recording.
        m3u8TranscodeFormat.setSliceOssObjectPrefix("");
        transcodeFormatList.add(m3u8TranscodeFormat);
        addLiveAppRecordConfigRequest.setTranscodeRecordFormats(transcodeFormatList);
        List transcodeTemplateList=new ArrayList();
        //The ID of the transcoding template.
        transcodeTemplateList.add("");
        addLiveAppRecordConfigRequest.setTranscodeTemplatess(transcodeTemplateList);
Note
  • If you only need to record the transcoded stream, you can Not Set the original stream (setRecordFormats).

  • When setting up recording transcoding streams (setTranscodeRecordFormats), you must also specify the transcoding template ID (setTranscodeTemplatess). The transcoding template needs to be configured. For more information, see Live stream transcoding.

  • When recording a transcoded stream, you need to set the transcoding to Stream Ingest Trigger when configuring the transcoding template.

  • The recording filename of the transcoded stream StreamName will be transformed into the format of StreamName plus _TranscodingTemplateID.

Custom recording policy

In Feature configuration, we configured the live stream recording feature. When stream ingest starts, the system begins to record the live content. We call this Automatic Recording.

In some cases, you may want to determine whether to record a live stream based on your business requirements. The live stream recording feature provides methods to address this issue. You can determine whether to record a live stream in the following scenarios:

  1. The Live Center calls back to query whether your business system needs to record the live content. Recording starts only after receiving a response confirming the need for recording. We call this On-demand Recording.

  2. Your business system sends notifications to the live streaming service to record the live content. We call this Manual Recording.

On-demand recording

按需录制

To implement on-demand recording, your business system needs to provide a URL address for live service invocation. For more information, see On-demand recording callback.

The following sample code provides an example on how to configure on-demand recording:

        //Set the OnD//Set the OnDemand parameter to 1 to enable on-demand recording through HTTP callbacks.
        addLiveAppRecordConfigRequest.setOnDemand(1);

Simultaneously call the AddLiveRecordNotifyConfig - Add domain-level recording callback configuration API to configure recording callbacks.

Sample code for configuring recording callbacks>>>

        //Replace the content in angle brackets with actual values
        AddLiveRecordNotifyConfigRequest addLiveRecordNotifyConfigRequest=new AddLiveRecordNotifyConfigRequest();
        //Specify a callback URL for on-demand recording.
        addLiveRecordNotifyConfigRequest.setOnDemandUrl("");
        addLiveRecordNotifyConfigRequest.setNotifyUrl("");
        addLiveRecordNotifyConfigRequest.setDomainName("");
        AddLiveRecordNotifyConfigResponse addLiveRecordNotifyConfigResponse = null;
        try {
            addLiveRecordNotifyConfigResponse = client.getAcsResponse(addLiveRecordNotifyConfigRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(addLiveRecordNotifyConfigResponse));
Important
  • <OnDemandUrl> specifies the callback request URL for on-demand recording. <NotifyUrl> specifies the callback URL address (including recording events and status callbacks).

  • The <NotifyUrl> parameter is required. If you want to receive only on-demand recording requests but do not want to call back recording events and status, you can set the <NotifyUrl> parameter to a URL that does not support the requested method.

Related API

Manual recording

To enable manual recording, you must disable the automatic recording feature. The following sample code provides an example:

        //Set the OnDemand parameter to 7 to disable automatic recording.
        addLiveAppRecordConfigRequest.setOnDemand(7);

Then during the live streaming, you can call the RealTimeRecordCommand - Real-time recording instruction API to start recording based on your business requirements.

Sample code for starting recording>>>

        //Replace the content in angle brackets with actual values 
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("start");
        realTimeRecordCommandRequest.setAppName("");
        realTimeRecordCommandRequest.setStreamName("");
        realTimeRecordCommandRequest.setDomainName("");
        RealTimeRecordCommandResponse realTimeRecordCommandResponse = null;
        try {
            realTimeRecordCommandResponse = client.getAcsResponse(realTimeRecordCommandRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(realTimeRecordCommandResponse));
Note
  • If you are recording a transcoded stream, you need to set <StreamName> in the form of StreamName plus _transcoding template ID.

  • setCommand("start"): starts recording.

Stop recording

Whether it is Automatic Recording, On-demand Recording, or Manual Recording, you can call the RealTimeRecordCommand - Real-time recording instruction API to actively stop recording.

        //Replace the content in angle brackets with actual values 
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("stop");
        realTimeRecordCommandRequest.setAppName("");
        realTimeRecordCommandRequest.setStreamName("");
        realTimeRecordCommandRequest.setDomainName("");
        RealTimeRecordCommandResponse realTimeRecordCommandResponse = null;
        try {
            realTimeRecordCommandResponse = client.getAcsResponse(realTimeRecordCommandRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(realTimeRecordCommandResponse));
Note
  • setCommand("stop"): stops the recording.

  • To actively stop recording, you also need to wait for the Stream Stitching duration before the recording file is generated.

  • If you are recording a transcoded stream, you need to set <StreamName> in the format of StreamName plus _transcoding template ID.

Stream splicing

If the same ingest endpoint is disconnected and then reconnects within the Stream Interruption Merge Duration (default 180 seconds), the recording content will be automatically merged into One recording file.

Note

A new recording file is generated only after the interruption duration for merge elapses.

You can configure the interruption duration for merge based on your business requirements:

//Unit: seconds. Valid values: 15 to 21600.
addLiveAppRecordConfigRequest.setDelayTime(<180>);

We recommend that you use the default value of 180 seconds. If the time is excessively short, many recordings may be generated when a live stream is frequently disconnected and reconnected due to reasons such as network fluctuations. If the time is excessively long, recordings may require a long period of time to be generated after a live stream ends.

In some specific business scenarios, you may Completely Not Want to wait for stream interruption splicing, but instead want to generate the recording immediately after the live stream ends. This can be achieved. You can set Callback Events for the stream ingest (for setting stream ingest callback events, see Live stream ingest callbacks), and when you receive the stream end notification, you can cancel stream interruption splicing by calling the RealTimeRecordCommand - Real-time recording instruction API.

        //Replace the content in angle brackets with actual values
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("cancel_delay");
        realTimeRecordCommandRequest.setAppName("");
        realTimeRecordCommandRequest.setStreamName("");
        realTimeRecordCommandRequest.setDomainName("");
        RealTimeRecordCommandResponse realTimeRecordCommandResponse = null;
        try {
            realTimeRecordCommandResponse = client.getAcsResponse(realTimeRecordCommandRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(realTimeRecordCommandResponse));
Note
  • If you are recording a transcoded stream, you need to set <StreamName> in the form of StreamName plus _transcoding template ID.

  • setCommand("cancel_delay") resets the stream interruption delay time, completely stops recording, and immediately generates a recording file.

Recording cycle configuration

After the live streaming duration Exceeds the set recording cycle, a new file will be generated (for example, if the live stream lasts 20 minutes and the recording cycle is set to 15 minutes, two recording files will be generated). The recording cycle supports 15-360 Minutes.

Sample code for configuring the recording cycle>>>

        List formatList=new ArrayList();
        AddLiveAppRecordConfigRequest.RecordFormat m3u8Format=new AddLiveAppRecordConfigRequest.RecordFormat();
        m3u8Format.setFormat("m3u8");
        m3u8Format.setOssObjectPrefix("");
        m3u8Format.setSliceOssObjectPrefix("");
       //Configure the recording cycle. Unit: seconds.
        m3u8Format.setCycleDuration(<900>);
        AddLiveAppRecordConfigRequest.RecordFormat mp4Format=new AddLiveAppRecordConfigRequest.RecordFormat();
        mp4Format.setFormat("mp4");
        mp4Format.setOssObjectPrefix("");
        //Configure the recording cycle. Unit: seconds.
        mp4Format.setCycleDuration(<1500>);
        formatList.add(mp4Format);
        formatList.add(m3u8Format);
        addLiveAppRecordConfigRequest.setRecordFormats(formatList);
Note

Note that in the above example, Two storage formats are configured, each with its own recording cycle. According to this configuration, if you stream for 20 Minutes, three recording files will be generated (one MP4 and two M3U8).

If the duration of a live stream does not exceed the recording cycle, the recording is generally generated after the live stream ends. If your business requires you to view the recording while the live stream is still in progress, you can refresh the recording content by calling the RealTimeRecordCommand - Real-time recording instruction API to force the recording to restart. If recording was in progress before the restart, a recording file is immediately generated.

Restart recording sample code>>>

        //Replace the content in angle brackets with actual values 
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("restart");
        realTimeRecordCommandRequest.setAppName("");
        realTimeRecordCommandRequest.setStreamName("");
        realTimeRecordCommandRequest.setDomainName("");
        RealTimeRecordCommandResponse realTimeRecordCommandResponse = null;
        try {
            realTimeRecordCommandResponse = client.getAcsResponse(realTimeRecordCommandRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(realTimeRecordCommandResponse));
Note
  • setCommand("restart"): restarts the recording.

  • If you are recording a transcoded stream, you need to set <StreamName> in the form of StreamName plus _transcoding template ID.

  • If you configure multiple storage formats for the recording of your live stream, this operation will refresh all storage formats together.

Recording content merge and fetch

ApsaraVideo Live allows you to Fetch recording content as files by creating a manifest based on time periods, or Merge multiple recording files within a start and end time period into a single file.

Note
  • Regardless of the storage format of recordings, live stream recording first slices the live stream into a number of TS segments and then composes them to generate recording files in the specified container format. With this attribute, you can create an M3U8 Manifest File to combine TS segment files, thereby achieving the merge and fetch of recorded content.

  • The recorded content must be in M3U8 storage format to be merged or fetched.

Call the CreateLiveStreamRecordIndexFiles - Create a manifest API to create a manifest for the recorded content.

Sample code for creating a recording content manifest file>>>

        CreateLiveStreamRecordIndexFilesRequest createLiveStreamRecordIndexFilesRequest=new CreateLiveStreamRecordIndexFilesRequest();
        createLiveStreamRecordIndexFilesRequest.setAppName("");
        createLiveStreamRecordIndexFilesRequest.setStreamName("");
        createLiveStreamRecordIndexFilesRequest.setDomainName("");
        createLiveStreamRecordIndexFilesRequest.setOssEndpoint("");
        createLiveStreamRecordIndexFilesRequest.setOssBucket("");
        createLiveStreamRecordIndexFilesRequest.setStartTime("");
        createLiveStreamRecordIndexFilesRequest.setEndTime("");
        createLiveStreamRecordIndexFilesRequest.setOssObject("");
        CreateLiveStreamRecordIndexFilesResponse createLiveStreamRecordIndexFilesResponse = null;
        try {
            createLiveStreamRecordIndexFilesResponse = client.getAcsResponse(createLiveStreamRecordIndexFilesRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(createLiveStreamRecordIndexFilesResponse));
Note
  • In the preceding sample code, an index file is created for the recording content of a live stream within a specific time range. <AppName> specifies the AppName. <StreamName> specifies the StreamName. <StartTime> specifies the beginning of the time range. <EndTime> specifies the end of the time range. The index file is stored in an OSS bucket. <OssEndpoint> specifies the OSS endpoint. <OssBucket> specifies the name of the OSS bucket. <IndexFiles/OssObject.m3u8> specifies the name of the manifest file.

  • to format: yyyy-MM-ddTHH:mm:ssZ (UTC).

Important
  • Creating a recording index requires that the live stream has been ingested. If there is no live streaming within the specified time or if the live stream name is incorrect, the creation of the recording index will fail.

  • The recording content contains files and information about the files, such as application names, stream names, and OSS storage paths. The file information (TS segment file information and created M3U8 manifest file information) is stored in ApsaraVideo Live, while the files (TS segment files and M3U8 manifest files) are stored in OSS.

  • The retention period of Files stored in OSS is determined by the storage configuration of OSS.

  • TS sharding File Information is only retained for 3 Months in the ApsaraVideo Live system. You can only select recording content from the last 3 months when creating M3U8 manifest files.

  • M3U8 Manifest Information is retained in the ApsaraVideo Live system for only 6 Months. You can only query information about manifest files created within the past 6 months.

  • To merge or fetch transcoding streams, you need to set the StreamName to StreamName plus _transcoding template ID format.

  • The OSS bucket that is specified by the <OssBucket> parameter must reside in the same region as the live center. Otherwise, you cannot use domain names to query information about the M3U8 manifest files.

Related API Operations

Recording management

View recordings

ApsaraVideo Live supports three methods to view recording files.

Method 1: View in the console

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Feature Management > Live Stream Recording to go to the Live Stream Recording page, and then click the Recording Management File tab.

  3. Select the streaming domain that you want to configure.

  4. Click the OSS tab.

    image

Method 2: View through API

Through the DescribeLiveStreamRecordIndexFiles - Query all index files recorded within a specific time period API. The following SDK sample code provides an example:

        //Replace the content in <> with actual values 
        DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
        IAcsClient client = new DefaultAcsClient(profile);
        DescribeLiveStreamRecordIndexFilesRequest describeLiveStreamRecordIndexFilesRequest=new DescribeLiveStreamRecordIndexFilesRequest();
        describeLiveStreamRecordIndexFilesRequest.setAppName("<AppName>");
        describeLiveStreamRecordIndexFilesRequest.setStreamName("<StreamName>");
        describeLiveStreamRecordIndexFilesRequest.setDomainName("<DomainName>");
        describeLiveStreamRecordIndexFilesRequest.setStartTime("<StartTime>");
        describeLiveStreamRecordIndexFilesRequest.setEndTime("<EndTime>");
        DescribeLiveStreamRecordIndexFilesResponse describeLiveStreamRecordIndexFilesResponse = null;
        try {
            describeLiveStreamRecordIndexFilesResponse = client.getAcsResponse(describeLiveStreamRecordIndexFilesRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }

        for(int i=0;i<describeLiveStreamRecordIndexFilesResponse.getRecordIndexInfoList().size();i++){
            System.out.println(new Gson().toJson(describeLiveStreamRecordIndexFilesResponse.getRecordIndexInfoList().get(i)));

        }
Important
  • Currently, only data from the last 6 Months can be queried.

  • EndTime and StartTime format: yyyy-MM-ddTHH:mm:ssZ (UTC), the interval cannot exceed 4 days.

Method three: OSS view

When you configure the recording feature, you have already specified the storage address of the recording files in OSS. If you need to view the recording files in OSS, see Listing files in OSS.

Delete recordings

ApsaraVideo Live stores Recording Information, such as AppName, StreamName, OSS file storage path, and the Files are stored in OSS. If you need to synchronously delete files stored in OSS when deleting recordings, you need to create the server role AliyunMTSVideoLifecycleRole and Precisely Grant the AliyunMTSVideoLifecycleRolePolicy system policy.

Detailed authorization procedure

Before you delete recordings in the ApsaraVideo Live console, you need to perform authorization. You need to create and authorize a RAM role in the RAM console by following the steps below, and then log on to the ApsaraVideo Live console to delete recordings.

Create a regular service role
  1. Log on to the RAM console as a RAM administrator.

  2. In the left-side navigation pane, select Identity Management > Role.

  3. On the Role page, click Create Role.

    image

  4. On the Create Role page, select Trusted Entity Type as Alibaba Cloud Service, then select the specific Alibaba Cloud service, and finally click OK.

    image

    Note

    Trusted Entity Name dropdown box, select "ApsaraVideo Media Processing".

  5. In the Create Role dialog box that appears, enter "AliyunMTSVideoLifecycleRole" in the Role Name field, and then click OK.image

  6. After the role is created, select the Basic Information Permission Management tab on the page of the role.

  7. Click Precise Authorization, and configure the following parameters:

    • Permission Type: System Policy

    • Enter the policy name: AliyunMTSVideoLifecycleRolePolicy

    After the configuration is complete, click OK.image

You can use the following three methods to delete recording files.

Method 1: Delete in the console

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Recordings.

  3. Select the domain name of the recording that you want to delete.

  4. Click the OSS tab, and select Delete.

    删除录制文件

  5. Click OK.

    By default, the sync delete option is not selected. If you select this option, when you delete a recording record in the ApsaraVideo Live console, the recording file stored in OSS will also be deleted.确定删除

Method 2: API deletion

Through the DeleteLiveStreamRecordIndexFiles - Delete live stream recording files operation. The following SDK sample code provides an example:

        DeleteLiveStreamRecordIndexFilesRequest deleteLiveStreamRecordIndexFilesRequest=new DeleteLiveStreamRecordIndexFilesRequest();
        deleteLiveStreamRecordIndexFilesRequest.setAppName("");
        deleteLiveStreamRecordIndexFilesRequest.setStreamName("");
        deleteLiveStreamRecordIndexFilesRequest.setDomainName("");

        List recordList=new ArrayList<>();
        //Add the index file ID.
        recordList.add("");
        deleteLiveStreamRecordIndexFilesRequest.setRecordIds(recordList);
        deleteLiveStreamRecordIndexFilesRequest.setRemoveFile("");
        DeleteLiveStreamRecordIndexFilesResponse deleteLiveStreamRecordIndexFilesResponse = null;
        try {
            deleteLiveStreamRecordIndexFilesResponse = client.getAcsResponse(deleteLiveStreamRecordIndexFilesRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }

        System.out.println(new Gson().toJson(deleteLiveStreamRecordIndexFilesResponse));
Important
  • is the manifest ID. For information about how to obtain the manifest ID, see View recordings.

Method three: OSS deletion

In most cases, we do not recommend that you directly delete recording files stored in OSS. If you want to delete a recording file stored in OSS, you can synchronize the deletion of files stored in OSS when you delete recording files through ApsaraVideo Live. If you need to directly delete recording files stored in OSS due to business requirements, see Delete files in OSS.

Other methods to delete files

Delete files that are more than 6 months old: Because you can only query recording information within the past 6 months, to delete files that are more than 6 months old, use OSS. For more information, see Delete files in OSS.

Delete expired recording files: Because media resources are stored in OSS buckets, you need to grant access permissions to delete recording files. You can click to authorize with one click. After authorization, submit a ticket. The backend team will configure the expiration time you need. For information about how to submit a ticket, see Contact us. After the expiration time is configured, the authorization for the automatic deletion of expired recording files is complete.

Note

In this step, you are assigned the role that grants ApsaraVideo Live the permissions to access Alibaba Cloud resources. If you accidentally delete the role, you can perform the authorization again.

References

When you encounter issues with live stream recording, see FAQ about live stream recording.

Using Java SDK, see Java SDK user guide.

For more information about recording callback features, see Live stream recording callback and On-demand recording callback.