Live stream recording refers to the process of converting ingested live streams into media segments in real time and storing them in Object Storage Service (OSS) or ApsaraVideo VOD. During the process, ApsaraVideo Live encapsulates live streams into video files in formats such as transport stream (TS), M3U8, MP4, and Flash Video (FLV). For video encoding, H.264, High Efficiency Video Coding (HEVC), and MPEG-4 are supported. For audio encoding, Advanced Audio Coding (AAC) and MP3 are supported. You can use the ApsaraVideo Live console or call API operations to select different recording methods, including automatic recording, scheduled recording, on-demand recording, and manual recording. After recording is complete, you can query the recording in the ApsaraVideo Live console, configure recording callbacks, or perform real-time processing of the recording. This topic describes information about live stream recording in detail, including the working principles, storage of recordings, and recording methods.
How live stream recording works
The live stream recording feature is used to generate recordings from live streams. When you use the feature, ApsaraVideo Live pulls the streams that you ingest and encapsulates the audio and video data into a number of separate media segments in the TS format. The TS segments are then stored in the OSS bucket that you specify or stored in ApsaraVideo VOD. ApsaraVideo Live complies with the following principles in the recording process:
ApsaraVideo Live only converts the container format of audio and video data from Real-Time Messaging Protocol (RTMP) or FLV to TS. However, ApsaraVideo Live never modifies the audio and video content, that is, the content of the coding layer. For example, if the live stream that you ingest is blurry, the recording is also blurry.
ApsaraVideo Live has the permissions to write recordings to your bucket. However, it has no permissions to modify or delete the task files in your bucket, including the stored recordings. You have the sole privilege to manage the recordings in your bucket.
Storage of recordings
You can store the recordings of a live stream in either ApsaraVideo VOD or OSS.
ApsaraVideo Live provides the following storage methods for recordings. You can use one of the methods based on your business requirements.
Store recordings in OSS: The OSS bucket that is used to store recordings must reside in the same region as the live center of your streaming domain. Cross-region recording is not supported.
Store recordings in ApsaraVideo VOD: Live streams are recorded and stored in ApsaraVideo VOD. The recordings are generated based on the VOD recording settings. You can use the online editing feature of ApsaraVideo VOD to edit and process the video content of live streams to produce short videos.
Container formats of recordings
The recording feature allows you to record live streams to files in the TS, M3U8, MP4, and FLV formats. Regardless of the container format, ApsaraVideo Live first slices the live streams into a number of separate TS segments and then composes them to generate recordings in the specified container format.
For the M3U8 format, ApsaraVideo Live stores both TS segments and M3U8 playlists in your bucket. This is because M3U8 playlists are only used as index files of the HTTP Live Streaming (HLS) protocol and audio and video data is separately stored in TS segments. For the MP4 and FLV formats, only the composed MP4 and FLV segments are stored in your bucket.
Limits
Store recordings in OSS
You can store recordings in OSS only if you create an OSS bucket that resides in the same region as the live center of your streaming domain. Cross-region recording is not supported. For more information, see Create an OSS bucket.
When you activate ApsaraVideo Live, the system considers that you authorize ApsaraVideo Live to write data to your OSS buckets by default. Therefore, ApsaraVideo Live has the permissions to store recordings in the bucket that you specify. If the permissions are accidentally deleted, you can reconfigure it by using the following methods:
Configure the permissions in the console. You must authorize ApsaraVideo Live to write video data to OSS before the video data can be stored in the bucket that you specify. For more information, see Grant the write permissions on OSS to ApsaraVideo Live.
Use Resource Access Management (RAM) to configure the permissions. For more information, see Create a RAM user and grant permissions to the RAM user.
Store recordings in ApsaraVideo VOD
You must activate ApsaraVideo VOD before you can store recordings in ApsaraVideo VOD. The region where you activate ApsaraVideo VOD must be the same as the region in which the live center of your streaming domain resides. For more information, see Activate ApsaraVideo VOD.
Audio and video encoding formats
ApsaraVideo Live needs to slice live streams into TS segments first. Therefore, the audio and video encoding formats of the live streams that you ingest must meet the requirements of the TS format. According to the FLV standard and ISO/IEC 13818-1 standard, the recording feature only supports the following encoding formats:
Video: H.264, HEVC, and MPEG-4
Audio: AAC and MP3
NoteIf the live streams contain audio and video data that is encoded in none of the preceding formats, the following unexpected exceptions may occur in the recording process: recording failures, black screen issues, and recordings with no sound.
Abnormal live streams
ApsaraVideo Live can generate recordings from normal live streams that meet the following requirements: The live streams are encoded in one of the supported formats and have stable frame rates and monotonically and linearly increasing timestamps. For live streams with occasional frame rate instability or timestamp jumps, ApsaraVideo Live can also generate recordings thanks to its wide compatibility.
However, ApsaraVideo Live may fail to generate recordings if an ingested live stream encounters the following serious exceptions: No video frame is detected for a long time, the timestamps do not increase in a monotonic and linear way, or the audio and video headers are missing.
Different recording methods and scenarios
ApsaraVideo Live provides the following recording methods. You can select a recording method based on your scenario.
Recording method | Scenario | Configuration | Storage |
You can record a specified live stream by specifying the stream name. You can also specify a domain name or application name to record live streams. |
| Two storage methods are supported:
| |
You can call an API operation to specify the start time and end time of recording. This way, live streams can be recorded as scheduled. | Calling of an API operation | OSS | |
You can configure a callback to control how each live stream is recorded. | Calling of an API operation | OSS | |
When you use this method, live streams are not recorded by default. You can call an API operation to manually record a live stream. | Calling of an API operation | OSS |
Recording at the domain name, application, or stream level
ApsaraVideo Live allows you to record live streams at the domain name, application, or stream level. You can specify a domain name or application name to record all live streams under the domain name or for the application. You can also specify a stream name to record the live stream.
You can configure multiple recording templates that specify recordings to store in OSS or ApsaraVideo VOD. However, if a live stream can match multiple recording templates at the same time, the recording templates take effect based on the priority. The following table describes the priority levels. A lower numeric value indicates a higher priority.
Priority | DomainName | AppName | StreamName |
1 | ✓ | ✓ | ✓ |
2 | ✓ | ✓ | * |
3 | ✓ | * | * |
A check mark (✓) indicates that the parameter has a value other than an asterisk (*) in the recording template that you configure in the console or in the recording rule that you configure by calling an API operation.
You cannot store the recordings of a live stream in both OSS and ApsaraVideo VOD. The following section describes how to store recordings in OSS or ApsaraVideo VOD.
Store recordings in OSS
ApsaraVideo Live console:
For information about how to use the ApsaraVideo Live console to store recordings in OSS, see Store recordings in OSS.
API calling:
Call the AddLiveAppRecordConfig operation to configure recording rules. For more information, see AddLiveAppRecordConfig.
Perform stream ingest. For more information, see Stream ingest, stream pulling, and streaming.
The following table describes other related API operations.
API operation
Description
Deletes a rule that specifies the recording configuration of an application if the rule is no longer needed.
Queries all configured rules.
Store recordings in ApsaraVideo VOD
ApsaraVideo Live console:
For information about how to use the ApsaraVideo Live console to store recordings in ApsaraVideo VOD, see Store recordings in ApsaraVideo VOD.
API calling:
Call the AddLiveRecordVodConfig operation to configure recording rules. For more information, see AddLiveRecordVodConfig.
Perform stream ingest. For more information, see Stream ingest, stream pulling, and streaming.
The following table describes other related API operations.
API operation
Description
Deletes the live-to-VOD configuration if the configuration is no longer needed.
Queries the live-to-VOD configuration.
Automatic recording based on scheduled tasks
Automatic recording based on scheduled tasks takes effect only when the StreamName parameter is specified.
If you want to record a live stream within a specified time period, you can call an API operation to automatically record the live stream as scheduled.
API calling:
Call the AddLiveAppRecordConfig operation to configure recording rules. For more information, see AddLiveAppRecordConfig.
Perform stream ingest. For more information, see Stream ingest, stream pulling, and streaming.
The following table describes other related API operations.
API operation | Description |
Deletes a rule that specifies the recording configuration of an application if the rule is no longer needed. | |
Queries all configured rules. |
Example
Assume that you create a recording task for which DomainName is set to example.com
, AppName is set to liveApp****
, and StreamName is set to liveStream****
. The recording task runs from 2019-02-15 09:00:00 to 2019-02-15 21:00:00 in UTC. The recording formats include M3U8 and MP4. The RecordFormat.1.CycleDuration parameter is not specified. In this case, the recording cycle for a single recording in the M3U8 format is 6 hours by default. The recording cycle for a single recording in the MP4 format is set to half an hour. The recordings are stored in an OSS bucket named liveBucket**** that resides in the endpoint oss-cn-shanghai.aliyuncs.com.
Call the AddLiveAppRecordConfig operation with the following parameters:
/?AppName=liveApp**** &DomainName=example.com &StreamName=liveStream**** &OssBucket=liveBucket**** &OssEndpoint=oss-cn-shanghai.aliyuncs.com &RecordFormat.1.Format=m3u8 &RecordFormat.2.Format=mp4 &RecordFormat.2.CycleDuration=1800 &StartTime=2019-02-15T01:00:00Z &EndTime=2019-02-15T13:00:00Z &<Common request parameters>
NoteThe values of the StartTime and EndTime parameters are in UTC. Remember to convert your local time to UTC.
Perform stream ingest.
NoteIf you specify a recording period, ApsaraVideo Live starts recording only when a live stream is ingested in that period.
The rule that specifies the recording period becomes invalid after the period ends.
On-demand recording
The principle of on-demand recording is that when a live stream is ingested, ApsaraVideo Live sends an HTTP callback to the preset AppServer. You can determine whether to record the live stream based on the content of the callback and dynamically change the recording format and recording cycle.
You need to develop the AppServer shown in the following figure to receive HTTP callbacks and determine whether to start recording based on your business logic.
API calling:
Call the AddLiveAppRecordConfig operation to configure recording rules. Set the OnDemand parameter to 1 to allow ApsaraVideo Live to send an HTTP callback asking whether to record a live stream.
Call the AddLiveRecordNotifyConfig operation to set the OnDemandUrl parameter.
Perform stream ingest.
The AppServer receives a callback of on-demand recording, determines whether to record the live stream based on your business logic, and then sends a response.
ApsaraVideo Live determines whether to start recording based on the response from the AppServer.
The following table lists the API operations used for on-demand recording.
API operation | Description |
Configures recording rules. | |
Deletes a rule that is no longer needed. | |
Queries all configured rules. | |
Configures the recording callbacks for a domain name, including event callbacks and callbacks of on-demand recording. | |
Deletes the recording callback configuration that is no longer needed for a domain name. | |
Queries the recording callback configuration for a domain name. | |
Updates the recording callback configuration for a domain name. | |
Defines the HTTP message that is sent upon a callback of on-demand recording. |
Example
Call the AddLiveAppRecordConfig operation to configure ApsaraVideo Live to automatically record all live streams under the domain name
example.com
for the application whose name isliveBucket****
./?AppName=liveApp**** &DomainName=example.com &OssBucket=liveBucket**** &OssEndpoint=oss-cn-shanghai.aliyuncs.com &RecordFormat.1.Format=m3u8 &<Common request parameters>
Call the AddLiveRecordNotifyConfig operation to set the OnDemandUrl parameter to
http://example.aliyundoc.com
./?DomainName=example.com &OnDemandUrl=http://example.aliyundoc.com &<Common request parameters>
Perform stream ingest.
Check the on-demand recording callback that is received by the AppServer. For more information, see Callbacks of on-demand recording.
GET /?app=liveApp****&domain=example.com&stream=liveStream****&vbitrate=2000&codec=h264 HTTP/1.1 Host: demo.aliyundoc.com User-Agent: Go-http-client/1.1
Determine whether to start recording based on the response in the callback. For more information, see Callbacks of on-demand recording.
Start recording if the following response is received:
{ "ApiVersion" : "1.0", "NeedRecord" : true }
Do not start recording if the following response is received:
{ "ApiVersion" : "1.0", "NeedRecord" : false }
If the OnDemandUrl parameter is not configured, no callback of on-demand recording is sent. In this case, no recording is generated.
Before you call the AddLiveRecordNotifyConfig operation to configure the recording callback, you must call the AddLiveAppRecordConfig operation to configure recording rules. Otherwise, the recording task cannot be started.
Manual recording
ApsaraVideo Live allows you to manually record a live stream. If a live stream is being recorded, you can also manually stop the recording of the live stream.
API calling:
Call the AddLiveAppRecordConfig operation to configure the recording rules. Set the OnDemand parameter to 7, which specifies that ApsaraVideo Live does not automatically record an ingested live stream.
Perform stream ingest.
Call the RealTimeRecordCommand operation to start recording.
(Optional) Call the RealTimeRecordCommand operation to stop recording.
The following table lists the API operations used for manual recording.
API operation | Description |
Configures recording rules. | |
Deletes a rule that is no longer needed. | |
Queries all configured rules. | |
Manually starts or stops recording. |
Example
Manually start recording
If the live stream
example.com/liveApp****/liveStream****
is being ingested, call the RealTimeRecordCommand operation to start recording./?AppName=liveApp**** &DomainName=example.com &StreamName=liveStream**** &Command=start &<Common request parameters>
Manually stop recording
If the live stream
example.com/liveApp****/liveStream****
is being recorded, call the RealTimeRecordCommand operation to stop recording./?AppName=liveApp**** &DomainName=example.com &StreamName=liveStream**** &Command=stop &<Common request parameters>
If the specified live stream is not being ingested or does not exist, an error is returned when you call the RealTimeRecordCommand operation to manually start recording.
If a live stream is interrupted after you manually record it, the recording stops. In addition, if automatic recording is not configured for the live stream, ApsaraVideo Live does not automatically record the live stream after it is resumed.
Obtain recordings
After a live stream is recorded, you can use the following methods to obtain the recordings.
Method 1: View the recordings in the ApsaraVideo Live console. For more information, see Manage recordings.
Method 2: Call the DescribeLiveStreamRecordIndexFiles operation to query all index files within a specific time period. The values of the StartTime and EndTime parameters are in UTC. Remember to convert your local time to UTC.
http(s)://live.aliyuncs.com/?Action=DescribeLiveStreamRecordIndexFiles &AppName=liveApp**** &DomainName=example.com &EndTime=2017-12-22T08:00:00Z &StartTime=2017-12-21T08:00:00Z &StreamName=liveStream**** &<Common request parameters>
Method 3: Call the AddLiveRecordNotifyConfig operation to configure a callback to receive an HTTP request whenever a recording is generated. You can process the recording in real time based on your business requirements. To do so, perform the following steps:
Call the AddLiveRecordNotifyConfig operation to configure ApsaraVideo Live to send a callback to
http://example.aliyundoc.com
each time a recording under the domain namealiyundoc.com
is generated./?DomainName=aliyundoc.com &NotifyUrl=http://example.aliyundoc.com &<Common request parameters>
After the configuration is complete, you receive a callback that is similar to the following example when a TS, MP4, or FLV recording is generated from the live stream
aliyundoc.com/live/teststream
:POST / HTTP/1.1 Host: live.example.com User-Agent: Go-http-client/1.1 { "domain": "aliyundoc.com", "app": "live", "stream": "teststream", "uri": "live/teststream/0_2017-03-08-23:09:46_2017-03-08-23:10:40.flv", "duration": 69.403, "start_time": 1488985786, "stop_time": 1488985840 }
Usage notes
If you want to know whether automatic recording at the domain name, application, or stream level or automatic recording based on scheduled tasks takes effect, you can configure recording callbacks. For more information, see Callbacks for live stream recording.
If you want to process each recording in real time, you can create index files. For more information, see Live stream recording.
A recording cycle is the maximum length of a recording. If the duration of a live stream exceeds the recording cycle, multiple recordings are generated. You can set the recording cycle to a value from 15 to 360 minutes. You can configure the recording cycle when you configure a recording template in the ApsaraVideo Live console. You can also call the AddLiveRecordVodConfig operation to configure the recording cycle for live streams that are recorded to ApsaraVideo VOD or call the AddLiveAppRecordConfig operation to configure the recording cycle for live streams that are recorded to OSS.
If a live stream is interrupted during a recording cycle but is resumed within 3 minutes, the stream is recorded in the same recording before and after the interruption. A new recording is generated for a live stream only if the live stream is interrupted for more than 3 minutes.
ApsaraVideo Live supports triggered stream pulling. If the streaming URL of the corresponding domain name is used for streaming, ApsaraVideo Live is automatically triggered to pull the live stream. If no one is watching the live stream, ApsaraVideo Live does not pull the live stream from the origin. In this case, automatic recording, on-demand recording, and manual recording are also disabled.