All Products
Search
Document Center

ApsaraVideo Live:Live stream snapshots

Last Updated:Aug 30, 2024

ApsaraVideo Live allows you to capture real-time snapshots during live streaming. This topic describes the snapshot feature of ApsaraVideo Live.

Prerequisites

Object Storage Service (OSS) is activated and an OSS bucket is created. The OSS bucket is used to store the snapshots that are captured during live streaming. For more information, see Activate OSS and Create a bucket.

Important

The bucket must reside in the same region as the live center of the streaming domain. Cross-region snapshot capture is not supported.

Snapshot rules

  • Snapshot rules for live streams are configured based on the AppName parameter of ingested streams. You can configure a snapshot rule for all ingested streams of a specific application.

    Note

    If the AppName parameter is set to an asterisk (*), the snapshot rule applies to all ingested streams of the specified domain name.

  • When you configure the snapshot feature, you can configure parameters to capture snapshots in overwrite mode or real-time mode.

    • In overwrite mode, the latest snapshot overwrites the existing snapshot.

    • In real-time mode, the latest snapshot is stored together with existing snapshots.

    • Live stream snapshots can be generated only in the JPG format.

      Note

      You must select at least one mode. The two modes can be selected at the same time.

Use the snapshot feature

Note

A newly configured snapshot template does not take effect on an ongoing live stream. The snapshot template takes effect only after you re-ingest the stream.

Configure the snapshot feature

You can configure the snapshot feature of ApsaraVideo Live by using one of the following methods:

  1. Configure the snapshot feature in the ApsaraVideo Live console. For more information, see Configure snapshots.

  2. Configure the snapshot feature by calling an API operation. The following sample code shows how to call the AddLiveAppSnapshotConfig operation to configure snapshot settings:

// Replace the placeholder values with the actual values.
DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
IAcsClient client = new DefaultAcsClient(profile);
AddLiveAppSnapshotConfigRequest addLiveAppSnapshotConfigRequest = new AddLiveAppSnapshotConfigRequest();
addLiveAppSnapshotConfigRequest.setDomainName("<DomainName>");
addLiveAppSnapshotConfigRequest.setAppName("<AppName>");
// The interval at which snapshots are captured. Valid values: 5 to 3600.
addLiveAppSnapshotConfigRequest.setTimeInterval(5);
addLiveAppSnapshotConfigRequest.setOssEndpoint("<Endpoint>");
addLiveAppSnapshotConfigRequest.setOssBucket("<BucketName>");
// The name of the OSS object to be generated when a snapshot is captured in overwrite mode. This object is to be overwritten each time when a snapshot is captured. The name must be less than 256 bytes in length. The name can contain variables, such as {AppName} and {StreamName}.
addLiveAppSnapshotConfigRequest.setOverwriteOssObject("<{AppName}/{StreamName}.jpg>");
// The name of the OSS object to be generated when a snapshot is captured in real-time mode. The name must be less than 256 bytes in length. The name can contain variables, such as {AppName}, {StreamName}, {UnixTimestamp}, and {Sequence}. You must specify one of {UnixTimestamp} and {Sequence}.
addLiveAppSnapshotConfigRequest.setSequenceOssObject("<{AppName}/{StreamName}/{UnixTimestamp}.jpg>");
try {
    AddLiveAppSnapshotConfigResponse addLiveAppSnapshotConfigResponse = client.getAcsResponse(addLiveAppSnapshotConfigRequest);
    System.out.println(addLiveAppSnapshotConfigResponse.getRequestId());
    // todo something.
} catch (ServerException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (ClientException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}          
Note
  • After you configure snapshot settings, snapshots are captured only for newly ingested streams. The captured snapshots are stored in the OSS bucket that is specified by the BucketName parameter. If you configure the paths of the snapshots captured in overwrite and real-time modes at the same time, the snapshots of the two modes are generated. The path of the snapshots captured in overwrite mode is <{AppName}/{StreamName}.jpg>. The path of the snapshots captured in real-time mode is <{AppName}/{StreamName}/{UnixTimestamp}.jpg>.

  • For more information about the differences between snapshots captured in overwrite mode and snapshots captured in real-time mode, see the Snapshot rules section of this topic.

Manage snapshots

You can manage snapshots by using one of the following methods:

1. Manage snapshots in the ApsaraVideo Live console. For more information, see Manage snapshots.

2. Manage snapshots by calling API operations. The following sample code shows how to use the server SDK for Java to call API operations to delete snapshots.

Perform the following steps:

  1. Query snapshots.

    Note

    To delete a snapshot, you must specify the timestamp of the snapshot. Before you delete the snapshot, you must query the timestamp of the snapshot.

    // Replace the placeholder values with the actual values. 
    DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
    IAcsClient client = new DefaultAcsClient(profile);
    DescribeLiveStreamSnapshotInfoRequest describeLiveStreamSnapshotInfoRequest=new DescribeLiveStreamSnapshotInfoRequest();
    describeLiveStreamSnapshotInfoRequest.setAppName("<AppName>");
    describeLiveStreamSnapshotInfoRequest.setStreamName("<StreamName>");
    describeLiveStreamSnapshotInfoRequest.setDomainName("<DomainName>");
    // The beginning of the time range to query. The time follows the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format and is displayed in UTC.
    describeLiveStreamSnapshotInfoRequest.setStartTime("<StartTime>");
    // The end of the time range to query. The time follows the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format and is displayed in UTC. The duration specified by the StartTime parameter and the EndTime parameter cannot exceed one day. 
    describeLiveStreamSnapshotInfoRequest.setEndTime("<EndTime>");
    DescribeLiveStreamSnapshotInfoResponse describeLiveStreamSnapshotInfoResponse = null;
    try {
        describeLiveStreamSnapshotInfoResponse = client.getAcsResponse(describeLiveStreamSnapshotInfoRequest);
    } catch (ClientException e) {
        e.printStackTrace();
    }
    System.out.println(new Gson().toJson(describeLiveStreamSnapshotInfoResponse));
    Important
    • Snapshot queries are limited to a single day within the past year. The duration specified by the StartTime parameter and the EndTime parameter cannot exceed one day.

    • If snapshots are captured in overwrite and real-time modes at the same time, you can query only the snapshots captured in real-time mode. In this case, you can view the snapshots captured in overwrite mode only in the OSS console. For more information, see List objects.

    • The DescribeLiveStreamSnapshotInfo operation does not support paged queries and can return a maximum of 100 entries at a time. By default, 10 entries are returned.

    • For more information about the DescribeLiveStreamSnapshotInfo operation, see DescribeLiveStreamSnapshotInfo.

  2. Delete snapshots.

    Note

    If you want to delete the corresponding snapshots that are stored in OSS when you delete snapshots in ApsaraVideo Live, you must create a Resource Access Management (RAM) role named AliyunMTSVideoLifecycleRole and attach the AliyunMTSVideoLifecycleRolePolicy system policy to the role. When you delete snapshots in ApsaraVideo Live, you delete the snapshot information, such as application name, stream name, and path of OSS objects. The snapshots themselves are stored in OSS. For more information, see the "Delete snapshots in the ApsaraVideo Live console" section of the Manage snapshots topic.

    // Replace the placeholder values with the actual values. 
    DefaultProfile profile = DefaultProfile.getProfile("<regionId>", "<ALIBABA_CLOUD_ACCESS_KEY_ID>", "<ALIBABA_CLOUD_ACCESS_KEY_SECRET>");
    IAcsClient client = new DefaultAcsClient(profile);        
    DeleteSnapshotFilesRequest deleteSnapshotFilesRequest=new DeleteSnapshotFilesRequest();
    deleteSnapshotFilesRequest.setAppName("<AppName>");
    deleteSnapshotFilesRequest.setStreamName("<StreamName>");
    deleteSnapshotFilesRequest.setDomainName("<DomainName>");
    // Specify whether to delete the corresponding snapshots stored in OSS.
    deleteSnapshotFilesRequest.setRemoveFile(true);
    List<Long> createTimestampLists=new ArrayList<>();
    // Specify the timestamp of the snapshot that you want to delete.
    // createTimestampLists.add(<Timestamp>);
    deleteSnapshotFilesRequest.setCreateTimestampLists(createTimestampLists);
    DeleteSnapshotFilesResponse deleteSnapshotFilesResponse= null;
    try {
        deleteSnapshotFilesResponse = client.getAcsResponse(deleteSnapshotFilesRequest);
    } catch (ClientException e) {
        e.printStackTrace();
    }
    System.out.println(new Gson().toJson(deleteSnapshotFilesResponse));
    Important
    • You can delete only snapshots that are captured within the past year.

    • You can delete the snapshots captured in overwrite mode only in the OSS console. For more information, see Delete objects.

    • For more information about the DeleteSnapshotFiles operation, see DeleteSnapshotFiles.

In the preceding example, the snapshot information in ApsaraVideo Live and the corresponding snapshots stored in OSS are deleted.

Instead of relying solely on the DescribeLiveStreamSnapshotInfo operation, we recommend that you configure callbacks for snapshot events and use callback parameters to save the snapshot information that includes the snapshot timestamps to your business system. This way, you can query the snapshot timestamps from your business system to delete snapshots based on the specified policy. For example, you can configure a scheduled task to delete the snapshots that are captured N months ago every day. For more information about snapshot callbacks, see the "Callbacks for live stream snapshot" section of the Manage callbacks topic.

References

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

For more information about the API operations of the live snapshot feature, see Live snapshot.