All Products
Search
Document Center

ApsaraVideo Live:Time shifting

Last Updated:Dec 16, 2024

Time shifting allows viewers to rewind a live stream that is still in progress or watch a show that is already completed. This topic provides an overview of time shifting and introduces how to use the feature.

How it works

Time shifting is available for live streams distributed over the HTTP Live Streaming (HLS) protocol. HLS breaks down a live stream into small transport stream (TS) segments and generates a manifest file with .m3u8 extension. The manifest records the URLs of TS segments in sequence. When a client requests the live stream, the server returns the up-to-date manifest, which allows the client to retrieve the latest TS segments based on the URLs.

When time shifting is enabled, the server stores the TS segments for a specified period. This allows the client to access and play back the earlier TS segments of the live stream.

Scenarios

ApsaraVideo Live provides two features that allow viewers to replay live content that has already been broadcast: live stream recording and time shifting.

Compared with live stream recording which records live content for on-demand viewing after a live stream ends, time shifting enables viewers to rewind a live stream that is still in progress. For example, when a sports event is being live streamed, viewers can jump back to any points to rewatch highlights or catch up on missed content.

Limitations

  • This feature supports a maximum of 100,000 concurrent viewers. If you want to increase the quota, submit a ticket.

  • Time shifting allows viewers to replay a live stream for up to 30 days after it was completed.

  • The feature is available in specific regions. For more information, see Supported regions.

Billing

You are charged for time shifting based on the volume and retention period of time-shifting data. For billing details, see Billing of time shifting.

Procedure

To use time shifting on the client side, perform the following steps:

  1. Enable time shifting for a live stream to store the corresponding live content.

  2. Send a request for previous content on the client side.

Enable time shifting

You can enable time shifting for a live stream in the ApsaraVideo Live console or through the API. After you enable the feature, the configuration takes effect only for newly ingested streams.

ApsaraVideo Live console

  1. Log on to the ApsaraVideo Live console.
  2. In the left-side navigation pane, choose Feature Management > Time Shifting.

  3. On the Time Shifting page, select a streaming domain.

  4. Click Add.

  5. Configure the parameters described in the following table.

    直播时移

    Parameter

    Description

    AppName

    The name of the application. The value must be the same as the application name specified in the ingest URL. The name can be up to 255 characters in length and may include digits, letters, hyphens (-), and underscores (_). It cannot start with a hyphen (-) or underscore (_).

    If you want to enable time shifting for all applications in the streaming domain, enter an asterisk (*).

    StreamName

    The name of the live stream.

    Transcoded Stream

    Specifies whether to enable the feature for the corresponding transcoded stream.

    Valid values: Source Stream Only and Transcoded Stream Included.

    Time-shifted Days

    The number of days for which the live content is retained. Viewers cannot replay the live content after the specified period.

    Valid values: 1, 3, 7, 15, and 30.

    Note

    The time-shifting configuration of a main streaming domain does not automatically apply to the associated sub-streaming domain. You need to enable the feature for the sub-streaming domain in the console.

  6. Click OK.

API

Call the OpenLiveShift operation to enable time shifting for a live stream.

 
// Replace placeholders with actual values.
DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
IAcsClient client = new DefaultAcsClient(profile);
OpenLiveShiftRequest openLiveShiftRequest = new OpenLiveShiftRequest();
openLiveShiftRequest.setDomainName("<DomainName>");
openLiveShiftRequest.setAppName("<AppName>");
openLiveShiftRequest.setStreamName("<StreamName>");
// The retention period of the live content. Unit: days. Valid values: 1 to 30. Default value: 7.
openLiveShiftRequest.setVision("<7>");
// Specify whether to ignore the time-shifting data of transcoded streams. Valid values: true and false. Default value: true.
openLiveShiftRequest.setIgnoreTranscode("<true>");
//
// Code for other features
//

try {
    OpenLiveShiftResponse openLiveShiftResponse = client.getAcsResponse(openLiveShiftRequest);
    System.out.println(new Gson().toJson(openLiveShiftResponse));
    // todo something.
} catch (ServerException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (ClientException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Note
  • To enable time shifting for all live streams under the specified domain name, set the AppName to an asterisk (*).

  • To enable time shifting for all live streams of the specified application, set the StreamName parameter to an asterisk (*).

  • You can call the DescribeLiveShiftConfigs operation to retrieve the time shifting settings for a domain name.

  • For information about how to use the server SDK for Java, see Use the server SDK for Java.

  • For more information about API parameters, see OpenLiveShift.

Send a request for playback

After you enable the time shifting feature for a live stream, ApsaraVideo Live stores the TS segments of the live stream for a specified period. Viewers can send playback requests with time-shifting parameters to access the previously streamed content. 

The playback request is formed by appending the following parameters to the end of the M3U8 URL of a live stream:

  • aliyunols=on: This parameter is required if the playback request is sent over Alibaba Cloud CDN.

  • Time-shifting parameter: The structure is lhs_{type}_{format}_{unit}_{zone}.

    The following table describes the variables in the time-shifting parameter.

    Variable

    Description

    type

    The type of time-shifting parameter. Valid values:

    • start: the start time of the playback.

    • end: the end time of the playback in live mode.

    • vodend: the end time of the playback in video-on-demand (VOD) mode. In VOD mode, the server returns a manifest that contains all TS segments in the requested timeframe and an endlist tag. This allows viewers to fast forward and rewind the video as desired. 

    • offset: the amount of time by which the live stream is rewound from the time of request.

    Important
    • You must specify a start parameter or an offset parameter. If both are specified, the playback prioritizes the offset parameter. 

    • The end and vodend parameters are optional. If neither of them is specified, the end of the manifest grows as the live content progresses. If both are specified, the playback prioritizes the vodend parameter.

    format

    The time format. Valid values:

    • unix: Unix timestamp.

    • human: human-readable time in yyyyMMddHHmmss format. 

    unit

    The unit of time. Valid values:

    • s: seconds.

    • ms: milliseconds.

    zone

    The time zone. Valid values: 0 to 9. For example, a value of 8 indicates UTC+8.

    Set this variable to 0 if the format is unix.

Request example 1

http://<DomainName>/<AppName>/<StreamName.m3u8>?aliyunols=on&lhs_offset_unix_s_0=300&auth_key=3sdda******

In this example, the time-shifting parameter is lhs_offset_unix_s_0=300, which indicates rewinding the live stream by 300 seconds.

Request example 2

http://<DomainName>/<AppName>/<StreamName.m3u8>?aliyunols=on&lhs_start_human_s_8=20171024160220&lhs_end_human_s_8=20171024160420

In this example, the time-shifting parameters are lhs_start_human_s_8=20171024160220 and lhs_end_human_s_8=20171024160420, which indicates playing live content from 16:02:20 to 16:04:20 on October 24, 2017.

Query the timeline of a live stream

If you want to know which periods are accessible for time-shifted viewing, you can send an HTTP Get request to query the timeline of a live stream. 

Sample code

// Replace placeholders with 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 table describes the parameters.

Parameter

Required

Description

DomainName

Yes

The streaming domain name.

aliyunols

Yes

Set the value to on.

app

Yes

The application name.

stream

Yes

The stream name.

format

Yes

Set the value to ts. 

lhs_start_unix_s_0

Yes

The Unix timestamp that specifies the beginning of the time range to query. Unit: seconds.

lhs_end_unix_s_0

Yes

The Unix timestamp that specifies the end of the time range to query. Unit: seconds.

auth_key

No

The access token. The value is generated by using the same encryption algorithm as generating a signed streaming URL. For more information, see URL signing.

Sample response

{
  "retCode": 0,
  "description": "success",
  "content": {
    "current": 1514269063,
    "timeline": [
      {
        "start": 1514269054,
        "end": 1514269058
      }
    ]
  }
}

Parameter

Description

current

The current system time. The player aligns the time with the returned value.

timeline

The valid time ranges for time shifting. 

start

The start time of a valid time range in Unix timestamp format. Unit: seconds. 

end

The end time of a valid time range in Unix timestamp format. Unit: seconds. 

Note
  • An ingested stream usually generates a single timeline object in which the start and end values are close to the actual start and end time of the live stream. However, multiple timeline objects may occur due to stream interruptions and network fluctuations.

  • You can also query the time-shifting data for a domain name in the ApsaraVideo Live console. For more information, see Usage statistics.

Advanced features

Time shifting for transcoded streams

To allow viewers to access transcoded streams for time-shifted viewing, enable time shifting for transcoded streams.

Procedure

  1. Configure transcoding for the source stream. For more information, see Live stream transcoding.

  2. Enable time shifting for the source stream and transcoded streams. Sample code:

// Specify whether to ignore the time-shifting data of transcoded streams. Valid values: true and false. Default value: true.
openLiveShiftRequest.setIgnoreTranscode("<false>"); 
  1. Add the time-shifting parameters to the URL of a transcoded stream to rewind the transcoded stream. Sample URL:

http://<DomainName>/<AppName>/<StreamName_transcoding template ID.m3u8>?aliyunols=on&lhs_offset_unix_s_0=300&auth_key=3sdda******
Note
  • Re-ingest the stream to activate the time shifting configuration for transcoded streams.

  • If transcoding is triggered by stream pulling, viewers cannot access previous segments of the transcoded stream by using time shifting unless the transcoding process has already been initiated by a prior playback request. To address this issue, you can configure transcoding to be triggered by stream ingest.

Important
  • Time shifting does not support streams with multi-bitrate transcoding.

Time shifting for encapsulated streams

You can utilize time shifting with live stream encapsulation.

Note

The encapsulation feature provided by ApsaraVideo Live supports multiple streaming protocols, such as CMAF and LL-HLS, to effectively reduce streaming latency. When it is enabled, the live stream is segmented into TS or CMAF chunks and distributed to viewers using specified HLS or LL-HLS protocols. The M3U8 manifest requested by viewers continuously updates with the URLs of these chunks to ensure seamless playback.

Compared to traditional HLS, LL-HLS can divide the stream into smaller sub-second segments, typically between 0.2 to 1 second in length. This fine-grained segmentation, alongside the capability to block-load M3U8 manifest and segments, helps achieve an end-to-end latency as low as 3 to 5 seconds. The CMAF format offers extensive support across a wide range of devices and browsers, and is compatible with the latest codecs such as H.265.

For more information about this feature, see Live stream encapsulation.

To rewind an encapsulated stream, add the time-shifting parameters to its URL. Sample URL:

http://<DomainName>/<AppName>/<StreamName-Container format.m3u8>?aliyunols=on&lhs_offset_unix_s_0=300&auth_key=3sdda******
Note
  • Re-ingest the stream to activate the time shifting configuration for encapsulated streams.

References

  • For information about the APIs related to the time shifting feature, see Time shifting.

  • To ensure a stable and smooth time-shifted viewing experience, we recommend that you use ApsaraVideo Player. For more information, see ApsaraVideo Live Player SDK.