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 |
|
| Suitable for post-production, such as live content editing, playback, and thumbnail generation. |
OSS |
|
| Suitable for live content storage and management. |
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.
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
- Log on to the ApsaraVideo Live console.
In the left-side navigation pane, select Feature Management > Recording. Click the VOD tab.
Select the streaming domain for which you want to configure recording, and click Add.
Configure the recording template.
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.
NoteThe 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.
NoteThe transcoding template must be created in the same region as the live center of the domain name.
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>");
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>");
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
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.
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.
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
- Log on to the ApsaraVideo Live console.
In the left-side navigation pane, select Feature Management > Recording. Click the OSS tab.
Select the streaming domain for which you want to configure recording, and click Add.
Configure the recording template.
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.
NoteAn 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.
NoteThere 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.
Optional. Configure transcoding settings.
You can use the transcoding feature of ApsaraVideo Live to transcode the live stream and record the transcoded stream.
ImportantThis will incur transcoding fees in ApsaraVideo Live.
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.
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
.
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.
The transcoding feature of ApsaraVideo Live is used in this process, which incurs transcoding fees.
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.
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.
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));
The recording is generated after the interruption duration threshold elapses.
If you are recording a transcoded stream, change
StreamName
toStreamName_Transcoding template ID
.
Configure interruption duration threshold
Configure the recording cycle
Merge and extract recordings
Manage recordings
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
If you encounter issues when using live stream recording, see FAQ about live stream recording.
For information about server SDK for Java, see Use the server SDK for Java.
For more information about recording callbacks, see Callbacks for live stream recording and Callbacks for on-demand recording.