All Products
Search
Document Center

ApsaraVideo Live:Live stream recording

Last Updated:May 26, 2025

Live stream recording allows you to record live streams in real time for future playback and editing.

Introduction

A live stream is transmitted from the ingest client to playback devices in real time. To watch the live content again after it has ended, use live stream recording to record streaming data received by the live center and save it to your specified storage location. ApsaraVideo Live supports storing the recordings in ApsaraVideo VOD or Object Storage Service (OSS).

How it works

Live stream recording processes ingested streams by splitting them into Transport Stream (TS) segments, and then encapsulates the data for storage. It complies with the following principles:

  • Live stream recording only modifies the container format of audio and video data, such as converting FLV to TS. The audio and video content at the coding layer remains unchanged. For example, if the live stream you push has visual issues such as a distorted screen, the recorded content will also reflect these issues.

  • ApsaraVideo Live only has the permission to write recording files to the storage location that you specify. It cannot modify or delete the files from that location.

Limitations

Audio and video codecs

As the streams are segmented into TS files for recording, the audio and video codecs of the ingested live streams must be compatible with the TS container format. Based on the FLV and ISO/IEC 13818-1 standards, the following codecs are supported:

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

  • Audio: AAC and MP3

If the live streams contain audio and video data encoded in incompatible formats, exceptions may occur, such as recording failures, black screen issues, and recordings without sound.

Processing of abnormal live streams

  • Standard streams: meet the encoding requirements and have stable frame rates and timestamps.

    ✅ Recording files are generated as expected.

  • Slightly abnormal streams: have occasional frame rate fluctuations or timestamp jumps.

    ✅ The system automatically accommodates minor anomalies.

  • Severely abnormal streams: have prolonged absence of video frames, disordered timestamps, or missing key frames.

    ❌ The system may fail to generate the recordings.

Storage location comparison

You can store the recordings in ApsaraVideo VOD or OSS. Select a storage method based on your business requirements:

Location

Supported recording methods

Container format

Scenarios

ApsaraVideo VOD

  • Automatic recording: Automatically records streams that meet the specified domain name, AppName, and StreamName conditions.

  • TS/M3U8 (default)

Suitable for post-production, such as live content editing, playback, and thumbnail generation.

OSS

  • Automatic recording: Automatically records streams that meet the specified domain name, AppName, and StreamName conditions.

  • On-demand recording: Records a live stream only when ApsaraVideo Live receives a callback response indicating that recording is required.

  • Manual recording: Recording is disabled by default. You can manually activate it through API calls.

  • TS/M3U8 (default)

  • MP4

  • FLV

  • CMAF

Suitable for live content storage and management.

Note

You cannot save the recordings of a live stream to ApsaraVideo VOD and OSS simultaneously.

Automatic recording rules

Automatic recording enables recording for streams that meet the specified rules. A rule consists of three conditions: domain name, AppName, and StreamName.

  • To record a specific stream, specify the domain name, AppName, and StreamName.

  • To record all streams under a specific application, specify the domain name and AppName, and set StreamName to an asterisk (*).

  • To record all streams under a specific domain name, specify the domain name, and set both AppName and StreamName to an asterisk (*).

You can configure multiple rules of automatic recording to save live content to ApsaraVideo VOD or OSS. If a stream matches multiple rules, the rule priorities are as follows (a smaller number indicates higher precedence):

Priority

Domain name

AppName

StreamName

1

Specified

Specified

Specified

2

Specified

Specified

Asterisk (*)

3

Specified

Asterisk (*)

Asterisk (*)

Billing

The costs for live stream recording are divided into two parts: monthly recording service fee and container format conversion fee. The default format of the recorded files is TS or M3U8. To store them in other formats, such as MP4 or FLV, fees are charged for conversion.

In addition, saving recordings to ApsaraVideo VOD or OSS also incurs storage fees in the corresponding service. For details, see Billing of data storage and Storage fees.

Save recordings to ApsaraVideo VOD

Prerequisites

  • ApsaraVideo VOD has been activated. Saving recordings to ApsaraVideo VOD incurs storage fees.

  • A storage bucket is created in the same region as the live center of the target streaming domain.

Feature configuration

Configure recording settings in the ApsaraVideo Live console or by API.

Note
  • For an ongoing live stream, the configuration takes effect only after you re-ingest the stream.

  • The recording file is generated 180 seconds after the stream is terminated. If a stream is interrupted but resumed within 180 seconds, the content before and after the interruption are automatically merged into a file.

In the console

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Feature Management > Recording. Click the VOD tab.

  3. Select the streaming domain for which you want to configure recording, and click Add.

  4. Configure the recording template.

    image

    Parameters

    Description

    Application Name

    • To configure recording for all applications under the domain name, enter an asterisk (*). 

    • To configure it for a specific application, the value must be the same as the AppName specified in the ingest URL of the stream.

    Stream Name

    • To configure recording for all streams under an application, enter an asterisk (*). 

    • To configure it for a specific stream, enter the stream name.

    Bucket

    The VOD buckets created in the current region are displayed. Select one of them. If not displayed, click the refresh button on the right.

    Recording Cycle

    The recording cycle specifies the maximum duration of a live-to-VOD file. Valid values: 15 to 360 minutes. When a recording exceeds 360 minutes, the system generates a new file according to the naming rules.

    The default duration of each TS segment is 30 seconds.

    Transcoding Settings

    Optional. Select a transcoding template retrieved from ApsaraVideo VOD. The recording will be transcoded in ApsaraVideo VOD.

    Note

    The transcoding template must be created in the same region as the live center of the domain name.

    Auto Merge

    When enabled, the system automatically merges recordings of multiple cycles into a single file after the live program ends. The original recordings are also retained.

    Auto merge uses the basic editing and transcoding features of ApsaraVideo VOD, which incur additional fees. For billing information, see Editing and production and Media transcoding.

    Transcoding Settings of Merged Video

    Select a transcoding template retrieved from ApsaraVideo VOD. The merged video will be transcoded in ApsaraVideo VOD.

    Note

    The transcoding template must be created in the same region as the live center of the domain name.

  5. Click OK.

By API

Call the AddLiveRecordVodConfig operation to add a live-to-VOD configuration.

Sample code of basic settings

// Replace the placeholder values with actual values.
DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
IAcsClient client = new DefaultAcsClient(profile);   
AddLiveRecordVodConfigRequest addLiveRecordVodConfigRequest=new AddLiveRecordVodConfigRequest();
addLiveRecordVodConfigRequest.setDomainName("<DomainName>");
addLiveRecordVodConfigRequest.setAppName("<AppName>");
addLiveRecordVodConfigRequest.setStreamName("<StreamName>");
addLiveRecordVodConfigRequest.setVodTranscodeGroupId("VOD_NO_TRANSCODE");
// The address of the VOD bucket.
addLiveRecordVodConfigRequest.setStorageLocation("<StorageLocation>");
AddLiveRecordVodConfigResponse addLiveRecordVodConfigResponse = null;
try {
    addLiveRecordVodConfigResponse = client.getAcsResponse(addLiveRecordVodConfigRequest);
} catch (ClientException e) {
    e.printStackTrace();
}
 System.out.println(new Gson().toJson(addLiveRecordVodConfigResponse));

In the preceding sample code, a Live-to-VOD configuration is added for a specific stream <StreamName> that belongs to the <AppName> application under the domain name <DomainName>. The recordings are saved to an ApsaraVideo VOD bucket <StorageLocation>. VOD_NO_TRANSCODE specifies that recordings are not transcoded.

Advanced settings: transcode recordings

Recordings stored in ApsaraVideo VOD are in the M3U8 format. To use other formats, set the ComposeVodTranscodeGroupId parameter to the ID of the transcoding template group created in ApsaraVideo VOD when you call the AddLiveRecordVodConfig operation.

Sample code

 addLiveRecordVodConfigRequest.setVodTranscodeGroupId("<TranscodeGroupId>");
Note

After you set up transcoding, the recordings are transcoded and the corresponding transcoded stream URLs are generated. The original recordings are retained. 

Advanced settings: merge recordings

When you call the AddLiveRecordVodConfig operation, you can configure the CycleDuration parameter to set the recording cycle. A recording file is generated for each recording cycle.

For example, if you set a recording cycle of 5 minutes, and the ingested stream lasts for 8 minutes, two recording files are generated.

Sample code for recording cycle setting

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

To merge recordings of multiple cycles into a file, set the AutoCompose parameter to ON and the ComposeVodTranscodeGroupId parameter to the ID of the transcoding template group created in ApsaraVideo VOD when you call the AddLiveRecordVodConfig operation.

Sample code for auto merge settings

addLiveRecordVodConfigRequest.setAutoCompose("ON");
addLiveRecordVodConfigRequest.setComposeVodTranscodeGroupId("<TranscodeGroupId>");
Important

Auto merge uses the basic editing and transcoding features of ApsaraVideo VOD, which incur additional fees. For billing information, see Editing and production and Media transcoding.

The recordings of multiple cycles will be merged into a new file, while the original recordings are also retained.

View recordings

You can only view recordings saved to ApsaraVideo VOD in the ApsaraVideo Live console. To manage the recordings, use media asset management of ApsaraVideo VOD. 

View recordings in the ApsaraVideo Live console:

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

  3. Select a streaming domain.

  4. Click the VOD tab to view recordings stored in the ApsaraVideo VOD.

    image

Save recordings to OSS

Prerequisites

  • OSS has been activated, and an OSS bucket has been created in the same region as the live center of the target streaming domain. Saving recordings to OSS incurs storage fees.

  • ApsaraVideo Live has obtained the permission to write data to OSS.

    The permission is automatically granted when you activate ApsaraVideo Live. If it is deleted by accident, click this link and click Authorize.

Important

We recommend that you use an Alibaba Cloud account to complete the authorization. If you use a RAM user account, the user must have the following permissions: ram:CreateRole, ram:GetRole, ram:ListPoliciesForRole, ram:AttachPolicyToRole. Granting these permissions to a RAM user poses a security risk.

Configure automatic recording rules

Configure automatic recording settings in the ApsaraVideo Live console or by API.

Note
  • For an ongoing live stream, the configuration takes effect only after you re-ingest the stream. 

  • The recording file is generated after the duration of stream interruption exceeds the specified threshold (180 seconds by default).

In the console

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, select Feature Management > Recording. Click the OSS tab.

  3. Select the streaming domain for which you want to configure recording, and click Add.

  4. Configure the recording template.

    image

    Table 1. Recording settings

    Parameter

    Description

    Application Name

    • To configure recording for all applications under the domain name, enter an asterisk (*). 

    • To configure it for a specific application, the value must be the same as the AppName specified in the ingest URL of the stream.

    Stream Name

    • To configure recording for all streams under an application, enter an asterisk (*). 

    • To configure it for a specific stream, enter the stream name.

    Note

    An asterisk (*) cannot be used as a wildcard character in a string.

    Storage Location

    Select an OSS bucket that is created in the same region as the live center of the domain name.

    Note

    There are two types of buckets:

    • Standard bucket: used for storage.

    • Media buckets: customized for ApsaraVideo Media Processing (MPS). It can automatically transcode stored videos.

    The two types of buckets are not distinguished in the bucket list. To use a media bucket, note down its name.

    Interruption Duration Threshold

    If the stream interruption duration exceeds the threshold, a new recording is generated. Otherwise, the content before and after the interruption are automatically merged.

    Valid values: 15 to 21600 seconds. 

    Storage Format

    Supported formats: FLV, M3U8, MP4, and CMAF.

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

    Naming Conventions

    Default storage path: record/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}.

    The system automatically add the transcoding template ID to StreamName.

    Example:

    If you set Application Name to liveApp**** and Stream Name to liveStream****, the storage path of recordings in the M3U8 format is record/liveApp****/liveStream****/{EscapedStartTime}_{EscapedEndTime }.

    Segment Length

    The duration of a TS segment. Unit: seconds. Default value: 30. Valid values: 5 to 30.

    Recording Cycle

    The recording cycle specifies the maximum duration of a live-to-VOD file. Valid values: 15 to 360 minutes. When a recording exceeds 360 minutes, the system generates a new file according to the naming rules. 

  5. Optional. Configure transcoding settings.

    You can use the transcoding feature of ApsaraVideo Live to transcode the live stream and record the transcoded stream.

    Important

    This will incur transcoding fees in ApsaraVideo Live.

    image

    Table 2. Transcoded stream recording settings

    Parameter

    Description

    Transcoded Stream Recording

    Turn on the switch to enable transcoding and recording.

    Storage Format

    Supported formats: FLV, M3U8, MP4, and CMAF.

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

    Naming Conventions

    Default storage path: transcodeRecord/{AppName}/{StreamName}/{EscapedStartTime }_{EscapedEndTime }. The system automatically adds _transcoding template ID to {StreamName}.

    Example:

    If you set AppName to liveApp****StreamName to liveStream****, and Transcoding Template ID to lld, the storage path of transcoded stream recordings in the M3U8 format is transcodeRecord/liveApp****/liveStream****_lld/{EscapedStartTime}_{EscapedEndTime }. 

    Segment Length

    The duration of a TS segment. Unit: seconds. Default value: 30. Valid values: 5 to 30.

    Recording Cycle

    The recording cycle specifies the maximum duration of a live-to-VOD file. Valid values: 15 to 360 minutes. When a recording exceeds 360 minutes, the system generates a new file according to the naming rules. 

    Transcoding Template ID

    You can select All Templates or up to 10 transcoding templates. 

    Make sure that the application name in the transcoding template is the same as in the recording template.

  6. Click OK.

By API

Call the AddLiveAppRecordConfig operation to add a recording template to store live content to OSS.

Sample code of basic settings

        // Replace the placeholder values with actual values.
        DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
        IAcsClient client = new DefaultAcsClient(profile);   
        AddLiveAppRecordConfigRequest addLiveAppRecordConfigRequest=new AddLiveAppRecordConfigRequest();
        addLiveAppRecordConfigRequest.setAppName("<AppName>");
        addLiveAppRecordConfigRequest.setStreamName("<StreamName>");
        addLiveAppRecordConfigRequest.setDomainName("<DomainName>");
        addLiveAppRecordConfigRequest.setOssEndpoint("<OssEndpoint>");
        addLiveAppRecordConfigRequest.setOssBucket("<OssBucket>");
        List<AddLiveAppRecordConfigRequest.RecordFormat> formatList=new ArrayList<AddLiveAppRecordConfigRequest.RecordFormat>();
        AddLiveAppRecordConfigRequest.RecordFormat m3u8Format=new AddLiveAppRecordConfigRequest.RecordFormat();
        m3u8Format.setFormat("m3u8");
        // The naming convention for the recording files in OSS.
        m3u8Format.setOssObjectPrefix("<record/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}>");
        // The naming convention for segments.
        m3u8Format.setSliceOssObjectPrefix("<record/{AppName}/{StreamName}/{UnixTimestamp}_{Sequence}>");
        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));

In the preceding sample code, a configuration is added for a specific stream <StreamName> that belongs to the <AppName> application under the domain name <DomainName>. The recordings are saved to an OSS bucket <OssBucket>. The storage format is m3u8.

Note

Set the OssEndpoint parameter to the endpoint of the OSS region. For details, see Regions and endpoints.

Record transcoded streams

By recording transcoded streams, you can adjust the video bitrate, increase the video compression rate, and reduce the size of recordings without compromising video quality. You can also store recordings of either the source streams, transcoded streams, or both.

Important

The transcoding feature of ApsaraVideo Live is used in this process, which incurs transcoding fees.

Sample code

        // Replace the placeholder values with actual values.        
        List<AddLiveAppRecordConfigRequest.TranscodeRecordFormat> transcodeFormatList=new ArrayList<AddLiveAppRecordConfigRequest.TranscodeRecordFormat>();
        AddLiveAppRecordConfigRequest.TranscodeRecordFormat m3u8TranscodeFormat=new AddLiveAppRecordConfigRequest.TranscodeRecordFormat();
        m3u8TranscodeFormat.setFormat("m3u8");
        // The naming convention for the transcoded recording files in OSS.
        m3u8TranscodeFormat.setOssObjectPrefix("<transcodeRecord/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}>");
        // The naming convention for transcoded segments.
        m3u8TranscodeFormat.setSliceOssObjectPrefix("<transcodeRecord/{AppName}/{StreamName}/{UnixTimestamp}_{Sequence}>");
        transcodeFormatList.add(m3u8TranscodeFormat);
        addLiveAppRecordConfigRequest.setTranscodeRecordFormats(transcodeFormatList);
        List<String> transcodeTemplateList=new ArrayList<String>();
        // The transcoding template ID.
        transcodeTemplateList.add("<lld>");
        addLiveAppRecordConfigRequest.setTranscodeTemplatess(transcodeTemplateList);
Note
  • If you want to record only transcoded streams, do not configure RecordFormats.

  • If you configure TranscodecordFormats, you must also set TranscodeTemplates to the ID of a live transcoding template

  • In the configured transcoding template, transcoding must be triggered by stream ingest

  • In the name of a transcoded stream recording, the StreamName field is changed to StreamName_Transcoding template ID

Configure custom recording rules

Automatic recording automatically records streams that meet the specified domain name, AppName, and StreamName conditions.

In addition to automatic recording, Recording to OSS also supports on-demand recording and manual recording:

  • On-demand recording: The live center sends a request to your business server to ask whether to record the live content. Recording starts only if your server responds affirmatively.

  • Manual recording: Your business server sends a request to the live center, asking it to start recording the specific live content.

You can configure on-demand and manual recording by APIs:

On-demand recording

按需录制

To implement on-demand recording, your business server must provide a callback URL for ApsaraVideo Live. For more information, see Callbacks for on-demand recording

Sample code

        // Set OnDemand to 1, which indicates that on-demand recording is enabled through HTTP callbacks.
        addLiveAppRecordConfigRequest.setOnDemand(1);

Call the AddLiveRecordNotifyConfig operation to configure recording callbacks for a domain name.

Sample code

        // Replace the placeholder values with actual values.
        AddLiveRecordNotifyConfigRequest addLiveRecordNotifyConfigRequest=new AddLiveRecordNotifyConfigRequest();
        // Specify a callback URL for on-demand recording.
        addLiveRecordNotifyConfigRequest.setOnDemandUrl("<OnDemandUrl>");
        addLiveRecordNotifyConfigRequest.setNotifyUrl("<NotifyUrl>");
        addLiveRecordNotifyConfigRequest.setDomainName("<DomainName>");
        AddLiveRecordNotifyConfigResponse addLiveRecordNotifyConfigResponse = null;
        try {
            addLiveRecordNotifyConfigResponse = client.getAcsResponse(addLiveRecordNotifyConfigRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(addLiveRecordNotifyConfigResponse));
Note
  • <OnDemandUrl> specifies the callback URL for on-demand recording. <NotifyUrl> specifies the callback URL that is used to receive notifications about recording events and status. 

  • The <NotifyUrl> parameter is required. If you want to receive only on-demand recording requests, set <NotifyUrl> to a URL that does not support the requested method. 

API references

Manual recording

To enable manual recording, you must disable automatic recording. Sample code:

        // Set the OnDemand parameter to 7, which disables automatic recording. 
        addLiveAppRecordConfigRequest.setOnDemand(7);

During live streaming, call the RealTimeRecordCommand operation and set Command to start to start recording. 

Sample code

        // Replace the placeholder values with actual values.
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("start");
        realTimeRecordCommandRequest.setAppName("<AppName>");
        realTimeRecordCommandRequest.setStreamName("<StreamName>");
        realTimeRecordCommandRequest.setDomainName("<DomainName>");
        RealTimeRecordCommandResponse realTimeRecordCommandResponse = null;
        try {
            realTimeRecordCommandResponse = client.getAcsResponse(realTimeRecordCommandRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(realTimeRecordCommandResponse));
Note

If you want to record a transcoded stream, change StreamName to StreamName_Transcoding template ID

Stop recording

No matter if you are using automatic, on-demand, or manual recording, you can call the RealTimeRecordCommand operation and set Command to stop to manually stop recording.

Sample code

        // Replace the placeholder values with actual values. 
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("stop");
        realTimeRecordCommandRequest.setAppName("<AppName>");
        realTimeRecordCommandRequest.setStreamName("<StreamName>");
        realTimeRecordCommandRequest.setDomainName("<DomainName>");
        RealTimeRecordCommandResponse realTimeRecordCommandResponse = null;
        try {
            realTimeRecordCommandResponse = client.getAcsResponse(realTimeRecordCommandRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(realTimeRecordCommandResponse));
Note
  • The recording is generated after the interruption duration threshold elapses. 

  • If you are recording a transcoded stream, change StreamName to StreamName_Transcoding template ID

Configure interruption duration threshold

If a live stream is interrupted but is re-ingested within the interruption duration threshold, the content generated before and after the interruption is automatically merged into one recording. By default, the interruption duration threshold is 180 seconds. 

For recording to OSS, you can configure a custom threshold. Sample code:

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

We recommend that you retain the default setting. If the time is too short, a large number of recordings will be generated when a live stream is frequently disconnected and reconnected due to network fluctuations. If it is too long, you need to wait for a long time to view the recording after a live stream ends.

Skip the interruption duration threshold

In some business scenarios, you may want to get the recordings immediately, instead of waiting until the interruption duration threshold elapses.

In this case, configure callbacks for stream ingest to receive notifications that indicate the ending of stream ingest. When the notification is received, call the RealTimeRecordCommand operation and set Command to cancel_delay to cancel the threshold mechanism and immediately generate a recording.

        // Replace the placeholder values with actual values.
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("cancel_delay");
        realTimeRecordCommandRequest.setAppName("<AppName>");
        realTimeRecordCommandRequest.setStreamName("<StreamName>");
        realTimeRecordCommandRequest.setDomainName("<DomainName>");
        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, change StreamName to StreamName_Transcoding template ID

Configure the recording cycle

After the duration of a live stream exceeds the recording cycle that you specify, a new recording file is generated. For example, if the live stream lasts for 20 minutes and the recording cycle is set to 15 minutes, two recordings are generated.

You can set a custom recording cycle ranging from 15 to 360 minutes. 

Sample code

        List<AddLiveAppRecordConfigRequest.RecordFormat> formatList=new ArrayList<AddLiveAppRecordConfigRequest.RecordFormat>();
        AddLiveAppRecordConfigRequest.RecordFormat m3u8Format=new AddLiveAppRecordConfigRequest.RecordFormat();
        m3u8Format.setFormat("m3u8");
        m3u8Format.setOssObjectPrefix("<record/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}>");
        m3u8Format.setSliceOssObjectPrefix("<record/{AppName}/{StreamName}/{UnixTimestamp}_{Sequence}>");
       // Configure the recording cycle. Unit: seconds.
        m3u8Format.setCycleDuration(<900>);
        AddLiveAppRecordConfigRequest.RecordFormat mp4Format=new AddLiveAppRecordConfigRequest.RecordFormat();
        mp4Format.setFormat("mp4");
        mp4Format.setOssObjectPrefix("<record/{AppName}/{StreamName}/{EscapedStartTime}_{EscapedEndTime}>");
        // Configure the recording cycle. Unit: seconds.
        mp4Format.setCycleDuration(<1500>);
        formatList.add(mp4Format);
        formatList.add(m3u8Format);
        addLiveAppRecordConfigRequest.setRecordFormats(formatList);
Note

In the preceding sample code, two storage formats are configured, each with a specific recording cycle. If a stream is ingested for 20 minutes, three recordings are generated, one in the MP4 format, and two in the M3U8 format. 

During live streaming, a recording is generated after the recording cycle ends. If you want to view the live content of an ongoing cycle before it ends, call the RealTimeRecordCommand operation and set Command to restart. The recording of the current cycle is stopped and the recording file of the previous content is immediately generated.

Sample code

        // Replace the content in <> with actual values. 
        RealTimeRecordCommandRequest realTimeRecordCommandRequest=new RealTimeRecordCommandRequest();
        realTimeRecordCommandRequest.setCommand("restart");
        realTimeRecordCommandRequest.setAppName("<AppName>");
        realTimeRecordCommandRequest.setStreamName("<StreamName>");
        realTimeRecordCommandRequest.setDomainName("<DomainName>");
        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, change StreamName to StreamName_Transcoding template ID

  • If you configure multiple storage formats, recordings are stored in the configured formats after the restart. 

Merge and extract recordings

Note

To use this feature, the configured storage formats must include M3U8.

Regardless of the storage format of recordings, ApsaraVideo Live first slices the live stream into a number of TS segments and then composes them in the specified container format. So, you can customize an M3U8 manifest that references TS segments to merge and extract the live content of a specified time range.

Call the CreateLiveStreamRecordIndexFiles operation to create a manifest for recorded TS segments.

Sample code

In the following sample code, a manifest is created for the live stream <StreamName> under the application <AppName>. The time range is from <StartTime> to <EndTime>. The manifest is stored in the OSS bucket named <OssBucket> at the endpoint <OssEndpoint>. The name of the manifest is <IndexFiles/OssObject.m3u8>.

Note
  • Specify the time in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

  • The OSS bucket must reside in the same region as the live center of the domain name. Otherwise, the recorded M3U8 manifests cannot be retrieved.

  • If you want to merge or extract content of a transcoded stream, change StreamName to StreamName_Transcoding template ID

        CreateLiveStreamRecordIndexFilesRequest createLiveStreamRecordIndexFilesRequest=new CreateLiveStreamRecordIndexFilesRequest();
        createLiveStreamRecordIndexFilesRequest.setAppName("<AppName>");
        createLiveStreamRecordIndexFilesRequest.setStreamName("<StreamName>");
        createLiveStreamRecordIndexFilesRequest.setDomainName("<DomainName>");
        createLiveStreamRecordIndexFilesRequest.setOssEndpoint("<OssEndpoint>");
        createLiveStreamRecordIndexFilesRequest.setOssBucket("<OssBucket>");
        createLiveStreamRecordIndexFilesRequest.setStartTime("<StartTime>");
        createLiveStreamRecordIndexFilesRequest.setEndTime("<EndTime>");
        createLiveStreamRecordIndexFilesRequest.setOssObject("<IndexFiles/OssObject.m3u8>");
        CreateLiveStreamRecordIndexFilesResponse createLiveStreamRecordIndexFilesResponse = null;
        try {
            createLiveStreamRecordIndexFilesResponse = client.getAcsResponse(createLiveStreamRecordIndexFilesRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(new Gson().toJson(createLiveStreamRecordIndexFilesResponse));
Important
  • You can create a manifest only after a live stream is ingested. If no live content is available within the specified time range or the name of the specified live stream is invalid, the manifest fails to be created. 

  • The M3U8 manifests and TS segments are stored in OSS. The retention period is determined by the storage configuration of OSS.

  • ApsaraVideo Live only stores information about M3U8 manifests and TS segments, including AppName, StreamName, OSS path, and start/end time.

  • ApsaraVideo Live stores information about TS segments only for three months. So, you can only create an M3U8 manifest that references the TS segments of the last three months. 

  • ApsaraVideo Live stores information about M3U8 manifests only for six months. So, you can query only manifests generated in the last six months.

API references

Manage recordings

View recordings

Use one of the following three methods to view recordings stored in OSS: 

In the ApsaraVideo Live console
  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, choose Feature Management > Recording. Click the Recordings tab. 

  3. Select a streaming domain.

  4. Click the OSS tab.

    image

By API

Call the DescribeLiveStreamRecordIndexFiles operation to query manifests generated in a specific time range.

Sample code

        // Replace the placeholder values 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
  • You can query only the data in the last six months. 

  • Specify EndTime and StartTime in the yyyy-MM-ddTHH:mm:ssZ format, displayed in UTC. The time range cannot exceed four days. 

In OSS

For information about how to use OSS to view recordings, see List objects

Delete recordings

ApsaraVideo Live stores only information about recordings, while OSS stores the actual files. If you want to delete files from OSS when you delete recording in ApsaraVideo Live, you must create the AliyunMTSVideoLifecycleRole role and attach the system policy AliyunMTSVideoLifecycleRolePolicy to the role. 

Click the link and click Authorize to grant permissions. You can also configure it in the RAM console:

Authorization in RAM console

  1. Log on to the RAM console with your Alibaba Cloud account.

  2. In the left navigation bar, choose Identities > Roles.

  3. On the Roles page, click Create Role.

  4. In the Select Role Type step, select Alibaba Cloud Service as the type of trusted entity. Then, click Next.image

  5. In the Configure Role step, configure the following parameters:

    • Set Role Type to Normal Service Role.

    • Enter AliyunMTSVideoLifecycleRole in the RAM Role Name field.

    • (Optional) Enter content in the Note field based on your needs.

    • Select Media Transcoding Service from the Select Trusted Service drop-down list.

    Click OK.image

  6. In the Finish step, click Input and Attach. On the role details page, click Precise Permission.

  7. In the Precise Permission panel, configure the following parameters:

    • Set Type to System Policy.

    • Enter AliyunMTSVideoLifecycleRolePolicy in the Policy Name field.

    Click OK.image

Then, use one of the following methods to delete recordings.

In the ApsaraVideo Live console
  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, choose Feature Management > Recording. Click the Recordings tab.

  3. Select the domain name for which you want to delete a recording.

  4. Click the OSS tab, find the recording that you want to delete, and click Delete in the Actions column.

    删除录制文件

  5. Click OK.

    By default, the "Also delete the recording file stored in OSS" option is not selected. If you select this option, the recording file stored in OSS is deleted simultaneously.确定删除

By API

Call the DeleteLiveStreamRecordIndexFiles operation to delete recordings.

<recordId> specifies the ID of the manifests to be deleted. To obtain the manifest ID, see View recordings.

Sample code

        DeleteLiveStreamRecordIndexFilesRequest deleteLiveStreamRecordIndexFilesRequest=new DeleteLiveStreamRecordIndexFilesRequest();
        deleteLiveStreamRecordIndexFilesRequest.setAppName("<AppName>");
        deleteLiveStreamRecordIndexFilesRequest.setStreamName("<StreamName>");
        deleteLiveStreamRecordIndexFilesRequest.setDomainName("<DomainName>");

        List<String> recordList=new ArrayList<>();
        // The ID of the manifest. 
        recordList.add("<recordId>");
        deleteLiveStreamRecordIndexFilesRequest.setRecordIds(recordList);
        deleteLiveStreamRecordIndexFilesRequest.setRemoveFile("<true>");
        DeleteLiveStreamRecordIndexFilesResponse deleteLiveStreamRecordIndexFilesResponse = null;
        try {
            deleteLiveStreamRecordIndexFilesResponse = client.getAcsResponse(deleteLiveStreamRecordIndexFilesRequest);
        } catch (ClientException e) {
            e.printStackTrace();
        }

        System.out.println(new Gson().toJson(deleteLiveStreamRecordIndexFilesResponse));
In OSS

In most cases, we do not recommend that you directly delete recording files in OSS. If you want to do so, see Delete objects

Note

You can only delete manifests generated in the last six months in the ApsaraVideo Live console or by calling the API. For manifests generated earlier, go to OSS to delete them.

Auto deletion from OSS

If you want to automatically delete expired recording files in an OSS bucket, submit a ticket. We will configure a validity period based on your requirements.

Make sure that you have completed authorization described in this section.

Use CDN for acceleration

To deliver the recorded content from the OSS bucket to viewers faster, use Alibaba Cloud CDN, which distributes videos to points of presence nearest to viewers, so they do not need to access the origin server of OSS. For details, see Access acceleration by using Alibaba Cloud CDN.

References