Time shifting allows you to play the content that has been streamed from the start time of live streaming to the current time. This topic describes how time shifting works and how to configure this feature.

How it works

Time shifting is based on the conventional HTTP Live Streaming (HLS) technology. A live stream is divided into TS segments and the TS segments are distributed to users by using the HLS protocol. The .m3u8 playlist that is requested by users contains TS segment URLs that are constantly updated. In conventional HLS streaming, TS segment URLs and TS files are not stored. As a result, earlier content that has been streamed cannot be played. After time shifting is enabled, TS segment URLs and TS files are stored in a database and an Object Storage Service (OSS) bucket for up to 30 days. This allows users to play the content that has been streamed from the start time of live streaming to the current time.

Configure time shifting

You can configure time shifting in the ApsaraVideo Live console. For more information, see Configure time shifting.

This feature allows a maximum of 100,000 users to view a live stream at the same time. If you want to raise the upper limit,submit a ticket.

Request parameters

An HLS streaming URL is in the format of http://domain/app/stream.m3u8 . To implement time shifting during live streaming, you must append time shifting parameters to the URL.

Note If you want to implement the time shifting feature by using Alibaba Cloud CDN, append the aliyunols parameter to the URL.

Time parameters

The name of a time parameter is in the lhs_{type}_{format}_{unit}_{zone} format. The name consists of the fixed prefix lhs_ and four variables. The variables are separated by underscores (_). The following table describes the variables.

Name Description
type The type of the time. Valid values:
  • start: The start time of live streaming.
  • end: The end time of live streaming.
  • vodend: The end time of video-on-demand (VOD) playback.
    Note If you set this variable to vodend, the video is played in VOD mode. In this case, all TS files that are generated within the specified time period are returned at a time, including the endlist tags.
  • offset: the forward offset time.
format The format of time. Valid values:
  • unix: the UNIX timestamp.
  • human: the time in the yyyyMMddHHmmss format. Example: 20170809230130.
unit The unit of time. Valid values:
  • s: seconds
  • ms: milliseconds
  • us: microseconds
  • ns: nanoseconds
zone The time zone. Valid values: 0 to 9.
  • The value indicates the number of hours to be added to Coordinated Universal Time (UTC).
  • A value of 0 indicates UTC.
  • A value of 8 indicates UTC+8.
Note When the format parameter is set to unix, set the zone parameter to 0.

Examples:

  • lhs_start_human_s_8=20170809200010
  • lhs_start_unix_s_0=1502280113
  • lhs_offset_unix_ms_0=1800000: indicates that the time is offset 30 minutes forward.

Sample request:

http://example.com/live/channel1.m3u8?aliyunols=on&lhs_start_human_s_8=20171024160220&lhs_end_human_s_8=20171024160420

Timeline query

  • You can query the time shifting duration and data volume that are supported for the specified domain name in the ApsaraVideo Live console. For more information, see Usage statistics.
  • You can also configure a query URL by setting the parameters that are described in the following table.
Name Description
url The query URL, in the http://{$domain}/openapi/timeline/query format. {$domain} indicates the name of the streaming domain.
method GET
params
  • aliyunols: required. Set the value to on.
  • app: required. The name of the application.
  • stream: required. The name of the live stream.
  • format: required. The format of the time shifting data to be queried. Supported formats are .ts and .flv.
  • lhs_start_unix_s_0: required. The start timestamp. Unit: seconds.
  • lhs_end_unix_s_0: required. The end timestamp. Unit: seconds.
Note If you have enabled CDN authentication, you must add the authentication parameters.
response, in the JSON format
  • current: the current system time. Your player aligns the time with the value of this parameter.
  • timeline: the duration to be queried. This value is an array. Each element of the array is a map that indicates a valid time shifting period. Each map contains the following fields:
  • timeline[i].start: the start timestamp of a valid time shifting period. Unit: seconds.
  • timeline[i].end: the end timestamp of a valid time shifting period. Unit: seconds.

Example:

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

Sample URL:

http://example.com/openapi/timeline/query?aliyunols=on&app=bbb&stream=cc&format=ts&lhs_end_unix_s_0=1513334270&lhs_start_unix_s_0=1513334255

Sample URL that contains the authentication information:

http://example.com/openapi/timeline/query?auth_key=1606204918-0-0-3e898a5f491fedb113d17aad7c091dde&aliyunols=on&app=zzb-test&stream=zzb-shiyi&format=ts&lhs_start_unix_s_0=1606200900&lhs_end_unix_s_0=1606202520
You can log on to the ApsaraVideo Live console or call an API operation to generate a signed URL:
  • Log on to the ApsaraVideo Live console. In the left-side pane, click Access Control. Then, click the URL Authentication tab. After the signed URL is generated, concatenate the URL with time shifting parameters.
  • ApsaraVideo Live also allows you to call an API operation to generate a signed URL. For more information,see Sample authentication code .