All Products
Search
Document Center

ApsaraVideo Live:Time shifting

Last Updated:Nov 27, 2025

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

Note
  • 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:

  1. Configure the time shifting feature.

    Note

    You must configure the feature to save live stream content and enable time shifting.

  2. Send a request from the client to use the time shifting feature.

Configure the time shifting feature

Configure time shifting in the console

  1. Log on to the ApsaraVideo Live console.

  2. In the navigation pane on the left, choose Feature Management > Time Shifting to open the Time Shifting page.

  3. Select the streaming domain that you want to configure.

  4. Click the Add button.

  5. Configure time shifting.

    直播时移

    The following table describes the parameters for the time shifting configuration.

    Parameter

    Description

    AppName

    The application name. The AppName must be the same as the AppName used for stream ingest to take effect. The name can be up to 255 characters in length and can contain digits, uppercase letters, lowercase letters, hyphens (-), and underscores (_). Hyphens and underscores cannot be at the beginning of the name. To configure time shifting for a domain, enter an asterisk (*).

    Stream Name

    The stream name.

    Transcoded Stream

    • Source Stream Only: Only the original stream supports time shifting.

    • Transcoded Stream Included: Both the original stream and transcoded streams support time shifting.

    Time-shifted Days

    ApsaraVideo Live provides the following options for time shifting duration.

    • 1 day

    • 3 days

    • 7 days

    • 15 days

    • 30 days

    Note
    • After you configure time shifting, you must re-ingest the stream for the configuration to take effect. The new time shifting settings do not apply to ongoing live streams.

    • You can directly access the time-shifted stream using the URL that corresponds to the streaming domain. For more information about the URL access specifications, see Time shifting rules.

    • If a primary streaming domain is associated with a sub-streaming domain, you must enable time shifting for the sub-domain. Otherwise, the time shifting configuration does not take effect for the sub-streaming domain.

  6. Click OK.

Configure time shifting using an API

// This file is auto-generated. Do not edit.
package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description
Note
  • You can set AppName to an asterisk (*) to apply the configuration to all live streams under the specified domain.

  • You can set StreamName to an asterisk (*) to apply the configuration to all live streams under the specified AppName.

  • After you add the configuration, you can call the DescribeLiveShiftConfigs operation to query the time shifting configurations of a specific domain.

  • For more information about how to use the Java SDK, see Java SDK User Guide.

  • You must re-ingest the stream for the configuration to take effect.

  • For more information about the parameters, see OpenLiveShift.

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.

Note
  • When you send a time shifting request through CDN, you must include the aliyunols=on parameter.

  • Currently, time-shifted playback supports only live streaming URLs in M3U8 format.

  • 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:

  • start: the playback start time.

  • end: the playback end time.

  • vodend: specifies the playback end time in video-on-demand (VOD) mode.

    Note

    Setting vodend indicates that playback is in VOD mode. This returns all TS segments within the specified time range at once and includes the endlist tag.

  • offset: the offset time for rewinding.

The time format for time shifting. Valid values:

  • unix: UNIX timestamp.

  • human: in YYYYMMDDHHMMSS format. Example: 20170809230130.

The time unit for time shifting. Valid values:

  • s: second.

  • ms: millisecond.

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=20170809200010

  • lhs_start_unix_s_0=1502280113

  • lhs_end_human_s_8=20170809200010

  • lhs_vodend_unix_s_0=1502280113

  • lhs_offset_unix_ms_0=1800000 (rewind by 30 minutes)

Important
  • You must specify either lhs_start or lhs_offset. If you specify both lhs_start and lhs_offset, the time-shifting playback is based on lhs_offset.

  • lhs_end/lhs_vodend is an optional parameter. If you do not specify lhs_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 specified lhs_end time.

  • If you specify lhs_vodend, playback continues in VOD mode until the specified lhs_vodend time. 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_end and lhs_vodend, lhs_vodend takes 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: http://{domain}/openapi/timeline/query. In the URL, {domain} is your streaming domain.

Parameters

  • aliyunols (required): on. (fixed field)

  • app (required): The application name.

  • stream (required): The stream name.

  • format (required): ts. (fixed field)

    Note

    Currently, the API only supports querying time-shift data in the ts format.

  • lhs_start_unix_s_0 (required): The UNIX timestamp of the start of the query time range. Example: 1724295706. Unit: seconds.

  • lhs_end_unix_s_0 (required): The UNIX timestamp of the end of the query time range. Example: 1724317306. Unit: seconds.

  • auth_key: The encryption key. This key uses The Same encryption algorithm as the key used for the streaming URL. If you are not familiar with authentication and encryption, see the Authentication Code Examples document.

Common error handling

  • 403: Check whether the encryption process for your auth_key value is correct.

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.

Note
  • 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******
Note
  • 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.

Important
  • 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.

Note

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******
Note
  • 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.