All Products
Search
Document Center

Time shifting

Last Updated: Mar 26, 2021

How it works

Time shifting is developed based on conventional HTTP Live Streaming (HLS) technology that divides a live stream into TS segments and distributes the TS segments to users by using the HLS protocol. The .m3u8 playlist dynamically requested by users contains TS segment URLs that are constantly updated. In conventional HLS, TS segment URLs and the corresponding TS files are not stored. As a result, the previous video content of the live streaming cannot be rewound. If you enable the time shifting feature for HLS streaming, TS segment URLs and the corresponding TS files are stored for up to 30 days. TS segment URLs are stored in a database and the corresponding TS files are stored in an Object Storage Service (OSS) bucket. This allows users to rewind the video content from the start time of the live streaming to the current time.

Enabling

You can enable the time shifting feature in the ApsaraVideo Live console.

Request parameters for time shifting

To implement time shifting during live streaming, you must add time shifting parameters to a conventional HLS URL such as http://domain/app/stream.m3u8.

The following setting is required:

aliyunols= on

Note

The preceding setting is required when you call a time shifting operation by using Alibaba Cloud CDN.

Time-related parameter

The time-related parameter is in the lhs_{type}_{format}_{unit}_{zone} format.

Note

The time-related parameter consists of four variables and a fixed prefix lhs_. The variables are separated by underscores (_). The following section describes the variables:

  • type: the type of the time. Valid values:

    • start: the start time of live streaming or VOD.

    • end: the end time of live streaming.

    • vodend: the end time of VOD. If you set this variable to vodend, the video is played back in VOD mode. In this case, all the TS files generated within a specified time period are returned at the same time, including the endlist tags.

    • offset: the forward offset time.

  • format: the format of the time. Valid values:

    • unix: the UNIX timestamp.

    • human: the human-readable time, such as 20170809230130.

  • unit: the unit of the time. Valid values:

    • s: second.

    • ms: millisecond.

    • us: microsecond.

    • ns: nanosecond.

  • zone: the time zone.

    • Valid values: an integer from 0 to 9. The value indicates the number of hours to add to UTC to obtain the standard time in the specified time zone. A value of 0 indicates the UTC time. A value of 8 indicates UTC+8. Set this parameter to 0 if the value of the format variable is unix.

Examples

  • lhs_start_human_s_8=20170809200010

  • lhs_start_unix_s_0=1502280113

  • lhs_offset_unix_ms_0=1800000: This setting indicates that the forward offset time is 30 minutes.

Sample requests

http://xxx.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 periods during which time shifting data was generated in a historical duration along the timeline of a specified stream.

  • URL: http://{$domain}/openapi/timeline/query

    Note

    Replace {$domain} with your streaming domain.

  • Method: GET

  • params

    • aliyunols: required. Set the value to on.

    • app: required. The name of the application to which the live stream belongs.

    • stream: required. The name of the live stream.

    • format: required. The format of the time shifting data to be queried. The supported formats are .ts and .flv.

    • lhs_start_unix_s_0: required. The start timestamp, measured in seconds since 00:00:00 Thursday, 1 January 1970.

    • lhs_end_unix_s_0: required. The end timestamp, measured in seconds since 00:00:00 Thursday, 1 January 1970.

      Note

      If CDN authentication is enabled, you must add the authentication parameters accordingly.

  • Response parameters in the JSON format

    • current: the current system time. Align the time of your player with the value of this parameter.

    • timeline: the duration for query. This parameter is an array. Each element of the array is a map, which indicates a valid time shifting period. Each map contains the following fields:

    • timeline[i].start: the start timestamp of a valid time shifting period, measured in seconds since 00:00:00 Thursday, 1 January 1970.

    • timeline[i].end: the end timestamp of a valid time shifting period, measured in seconds since 00:00:00 Thursday, 1 January 1970.

  • Example

    http://{$domain}/openapi/timeline/query?aliyunols=on&app=bbb&stream=cc&format=ts&lhs_end_unix_s_0=1513334270&lhs_start_unix_s_0=1513334255

    Sample signed URL:

    http://{$domain}/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
  • Generation of a signed URL

    • Generate a signed URL in the ApsaraVideo Live console

      Log on to the ApsaraVideo Live console, go to the URL Authentication tab under Access Control, and then generate a signed URL. Add time shifting parameters to the generated URL to obtain the required URL.

      Generate a signed URL
    • Generate a signed URL by calling the specific API operation

      ApsaraVideo Live allows you to generate signed URLs by calling the specific API operation. For more information, see Sample authentication code.

  • Response

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