Time shifting lets you play back a live stream from its start time to the current time. This topic describes how time shifting works and how to send requests.
Scenarios
The time shifting feature allows viewers to rewind a live stream during playback. For example, during a live sports broadcast, viewers can use time shifting to re-watch parts of the event, similar to watching a movie or TV show.
How it works
ApsaraVideo Live streams are sliced into Transport Stream (TS) segments and distributed to viewers using the HTTP Live Streaming (HLS) protocol. A viewer's request for an M3U8 playlist contains a list of TS segment addresses that is constantly updated. For standard HLS live streaming, the TS segment addresses and their corresponding TS files are not saved. This means you cannot rewind the live stream. When you enable the time shifting feature, the TS segment information and files are saved. This lets you rewind the video from the start of the live stream to the current time.
Limits
Time shifting supports a maximum of 100,000 concurrent viewers. To support more viewers, submit a ticket. For more information about how to submit a ticket, see Contact us.
Use the feature
Using the time shifting feature incurs time shifting fees. You are charged based on the amount of time-shifted data written and the specifications of time-shifted playback. For more information about the billing rules, see Time shifting fees.
For more information about the regions that support the time shifting feature, see Supported regions.
To use time shifting, you must complete the following two steps:
Configure the time shifting feature.
NoteYou must configure the feature to save live stream content and enable time shifting.
Send a request from the client to use the time shifting feature.
Configure the time shifting feature
Use the time shifting feature
After you configure time shifting, ApsaraVideo Live saves the TS segment files of the live stream. The client can then send a time-shifted playback request to play back the live content.
The following example shows a time-shifted playback request:
http://<DomainName>/<AppName>/<StreamName.m3u8>?aliyunols=on&lhs_offset_unix_s_0=300&auth_key=3sdda******As shown in the example, the time shifting request is similar to a live streaming URL for an M3U8 file but includes two additional parameters. aliyunols=on is a fixed field, and lhs_offset_unix_s_0=300 indicates a rewind of 300 seconds.
When you send a time shifting request through CDN, you must include the
aliyunols=onparameter.Currently, time-shifted playback supports only live streaming URLs in
M3U8format.You can use ApsaraVideo Player to play back time-shifted content. For more information about how to use ApsaraVideo Player, see Player SDK.
In this example, the live content is rewound by 300 seconds. When you play back time-shifted content, you can use the lhs_offset_unix_s_0 parameter to set the playback time. The parameter format is lhs_{type}_{format}_{unit}_{zone}.
The following table describes the variables in the parameter.
type | format | unit | zone |
The time type. Valid values:
| The time format for time shifting. Valid values:
| The time unit for time shifting. Valid values:
| The time zone. Valid values: 0 to 9, which indicates UTC+*. 0 indicates UTC, and 8 indicates China Standard Time. Note If you set format to unix, set zone to 0. |
The following examples show the time shifting parameters:
lhs_start_human_s_8=20170809200010lhs_start_unix_s_0=1502280113lhs_end_human_s_8=20170809200010lhs_vodend_unix_s_0=1502280113lhs_offset_unix_ms_0=1800000(rewind by 30 minutes)
You must specify either
lhs_startorlhs_offset. If you specify bothlhs_startandlhs_offset, the time-shifting playback is based onlhs_offset.lhs_end/lhs_vodendis an optional parameter. If you do not specifylhs_end/lhs_vodend, playback continues in live mode until the stream ingest ends.If you specify
lhs_end, playback continues in live mode until the specifiedlhs_endtime.If you specify
lhs_vodend, playback continues in VOD mode until the specifiedlhs_vodendtime. In VOD mode, all TS segments are returned at once. You can use the player progress bar to fast forward and rewind.If you specify both
lhs_endandlhs_vodend,lhs_vodendtakes precedence.
If you do not know the specific start and end times for your business, you can query the time shifting timeline to obtain them.
The following example shows how to query the time shifting timeline:
// Replace the values in angle brackets (<>) with your actual values.
http://<DomainName>/openapi/timeline/query?aliyunols=on&app=<AppName>&stream=<StreamName>&format=ts&lhs_start_unix_s_0=<StartTime>&lhs_end_unix_s_0=<endTime>&auth_key=<auth_key>The following is an example:
Name | Description |
Request method | GET |
URL | The request URL. Example: |
Parameters |
|
Common error handling |
|
The following example shows a sample response:
{
"retCode": 0,
"description": "success",
"content": {
"current": 1514269063,
"timeline": [
{
"start": 1514269054,
"end": 1514269058
}
]
}
}Parameter | Description |
current | The current system time. The player can use this field to synchronize the time. |
timeline | The valid time shifting period, which includes the start and end UNIX timestamps. |
start | The start time of the valid segment (UNIX timestamp). Unit: seconds. |
end | The end time of the valid segment (UNIX timestamp). Unit: seconds. |
Typically, one stream ingest generates one timeline object. The start time is close to the live stream start time, and the end time is close to the current time or the live stream end time. However, multiple timeline objects may be generated due to factors such as stream interruptions, re-ingestion, or network fluctuations.
You can query the time shifting data volume for a specific domain in the console. For more information, see Query usage.
Advanced usage
Play back transcoded streams with time shifting
You can use the time shifting feature with the transcoding feature to play back transcoded streams. To play back transcoded streams with time shifting, you must first configure transcoding. For more information about how to configure transcoding, see Live stream transcoding.
This section assumes that you have completed the transcoding configuration.
When you configure time shifting, you must also generate time-shifted data for transcoded streams. The following example shows the sample code:
// Specifies whether to ignore the corresponding transcoded stream when generating time-shifted data. Valid values: true and false. Default value: true.
openLiveShiftRequest.setIgnoreTranscode("<false>");To enable time-shifted playback, Add Time-shifting Parameters to the transcoded stream URL.
The following example shows a playback URL:
http://<DomainName>/<AppName>/<StreamName_TranscodingTemplateID.m3u8>?aliyunols=on&lhs_offset_unix_s_0=300&auth_key=3sdda******You must re-ingest the stream to play back the transcoded stream with time shifting.
For transcoding configurations that are triggered by stream pulling, playing back a transcoded stream with time shifting does not trigger transcoding. You must play the live transcoded stream in advance to trigger transcoding. You can also configure transcoding to be triggered by stream ingest.
Currently, the time shifting feature does not support multi-bitrate transcoded streams.
Play back encapsulated streams with time shifting
To play back encapsulated streams with time shifting, use the Time Shifting feature in conjunction with the Encapsulation feature.
ApsaraVideo Live supports the live stream encapsulation service. This service supports playback protocols such as CMAF and Low-Latency HTTP Live Streaming (LL-HLS) to effectively reduce live streaming latency. After you enable live stream encapsulation, the ApsaraVideo Live stream is sliced into TS or CMAF segments. The segments are distributed to viewers using the specified HLS or LL-HLS protocol. The M3U8 playlist that a viewer requests contains a list of segment addresses that is constantly updated. Compared with HLS, LL-HLS can slice streams into smaller parts with durations from 0.2 to 1 second. It also supports blocking loads for M3U8 playlists and parts. This achieves an end-to-end latency as low as 3 to 5 seconds. Compared with the TS format, the CMAF container format is supported by a wider range of devices and browsers. It also supports newer codecs, such as H.265.
If you are not familiar with the live stream encapsulation feature, see Live stream encapsulation.
This section assumes that you have completed the live stream encapsulation configuration.
To play back encapsulated streams with time shifting, you do not need to modify the time shifting configuration. You can simply add the time shifting parameters to the encapsulated stream URL.
The following example shows a playback URL:
http://<DomainName>/<AppName>/<StreamName-ContainerFormat.m3u8>?aliyunols=on&lhs_offset_unix_s_0=300&auth_key=3sdda******You must re-ingest the stream to play back the encapsulated stream with time shifting.
To play back an encapsulated and transcoded stream with time shifting, you can simply add the time shifting parameters to the encapsulated and transcoded stream URL.
References
For more information about the APIs for time shifting, see Time shifting.
