Live watermark

Updated at:
Copy as MD

ApsaraVideo Live lets you overlay image watermarks on live streams for copyright protection or advertising.

Use cases

Copyright protection: Add watermarks to your live videos to deter unauthorized use.

Advertising: Display promotional labels or event details on your live stream.

Prerequisites

  • To use the watermark feature, you need a watermark image. Only image watermarks are supported. If you need a text watermark, create a PNG image of the text. Watermark images can be in JPG or PNG format.

  • You must have a URL for the watermark image. ApsaraVideo Live fetches images from URLs and does not support direct uploads. Ensure this URL remains accessible.

Feature configuration

To use watermarks, configure a Watermark Templates and a Watermark Rules.

A watermark template defines a watermark's appearance, including position, transparency, and image URL.

A watermark rule associates an AppName and StreamName with a specific watermark template.

Configure a watermark template

You can configure a watermark template in the console or by calling an API.

Configure in the console

  1. Log on to the ApsaraVideo Live console.

  2. In the left-side navigation pane, choose Feature Management > Watermarks. On the Watermarks page, click the Watermark Templates tab.

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

  4. Click Add Watermark Template and configure the template.

    image

    Preview the watermark effect in the preview area. Adjust the screen size, watermark size, and position for a real-time preview. The following table describes the template parameters.

    Parameter

    Description

    Template Name

    The name of the watermark template. The name can be up to 30 characters long and can contain Chinese characters, letters, digits, hyphens (-), and underscores (_).

    Watermark Description

    The description of the watermark. The description can be up to 128 characters long and can contain Chinese characters, letters, digits, and special characters.

    Watermark Material

    Enter the URL of the watermark image. The URL must start with http:// or https://.

    Use a permanent URL from Object Storage Service (OSS) or another source with long-term authentication.

    Coordinate Origin

    The anchor corner of the watermark in the output video. The watermark is offset from this corner. Valid values:

    • Top right (default)

    • Bottom right

    • Top left

    • Bottom left

    Preview Screen Size (Width × Height)

    The dimensions of your actual video, used to preview the watermark position and appearance. Unit: pixels.

    Watermark Size (Width × Height)

    The size of the watermark image. The width is automatically scaled based on the height.

    • Value range: [0, 4096].

    • Unit: pixels.

    Horizontal Offset

    The horizontal offset of the watermark from the coordinate origin in the output video.

    • Value range: [0, 4096].

    • Unit: pixels.

    Vertical Offset

    The vertical offset of the watermark from the coordinate origin in the output video.

    • Value range: [0, 4096].

    • Unit: pixels.

    Transparency

    The watermark opacity. 0 means fully transparent, and 100 means fully opaque.

    • Value range: [0, 100].

    • Unit: percent.

  5. Click save to complete the watermark template configuration.

  6. After you add the watermark template, a dialog box prompts you to add a watermark rule. You can click Add to create a watermark rule for this template. For more information about how to configure a watermark rule, see Configure a watermark rule.

    Note

    After creating a watermark template, you must associate it with a watermark rule. The AppName and StreamName in the rule must match those in the ingest URL. To apply the changes, restart the stream ingest.

Configure by using an API

Watermark template parameters are complex. We recommend using the console's visual interface to preview the watermark position, even when configuring templates programmatically.

  1. First, add a watermark template in the ApsaraVideo Live console.

  2. After configuring the parameters, query the template's configuration.

    // This file is auto-generated, don't edit it. Thanks.
    package demo;
    
    import com.aliyun.auth.credentials.Credential;
    import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
    import com.aliyun.core.http.HttpClient;
    import com.aliyun.core.http.HttpMethod;
    import com.aliyun.core.http.ProxyOptions;
    import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
    import com.aliyun.sdk.service.live20161101.models.*;
    import com.aliyun.sdk.service.live20161101.*;
    import com.google.gson.Gson;
    import darabonba.core.RequestConfiguration;
    import darabonba.core.client.ClientOverrideConfiguration;
    import darabonba.core.utils.CommonUtil;
    import darabonba.core.TeaPair;
    
    //import javax.net.ssl.KeyManager;
    //import javax.net.ssl.X509TrustManager;
    import java.net.InetSocketAddress;
    import java.time.Duration;
    import java.util.*;
    import java.util.concurrent.CompletableFuture;
    import java.io.*;
    
    public class DescribeLiveStreamWatermarks {
        public static void main(String[] args) throws Exception {
    
            // Configure the HttpClient.
            /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                    .connectionTimeout(Duration.ofSeconds(10)) // The timeout period for a connection. Default value: 10 seconds.
                    .responseTimeout(Duration.ofSeconds(10)) // The timeout period for a response. Default value: 20 seconds.
                    .maxConnections(128) // The connection pool size.
                    .maxIdleTimeOut(Duration.ofSeconds(50)) // The timeout period for the connection pool. Default value: 30 seconds.
                    // Configure the proxy.
                    .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<your-proxy-hostname>", 9001))
                            .setCredentials("<your-proxy-username>", "<your-proxy-password>"))
                    // For an HTTPS connection, you must configure a certificate or ignore the certificate by using .ignoreSSL(true).
                    .x509TrustManagers(new X509TrustManager[]{})
                    .keyManagers(new KeyManager[]{})
                    .ignoreSSL(false)
                    .build();*/
    
            // Configure the credentials for authentication, including the AccessKey ID, AccessKey secret, and security token.
            StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                    // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                    .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                    .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                    //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use a Security Token Service (STS) token.
                    .build());
    
            // Configure the client.
            AsyncClient client = AsyncClient.builder()
                    .region("<your-region-id>") // The region ID.
                    //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                    .credentialsProvider(provider)
                    //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                    // The client-level configuration. You can overwrite the endpoint and HTTP request parameters.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                      // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                    .setEndpointOverride("live.aliyuncs.com")
                            //.setConnectTimeout(Duration.ofSeconds(30))
                    )
                    .build();
    
            // Set the parameters for the API request.
            DescribeLiveStreamWatermarksRequest describeLiveStreamWatermarksRequest = DescribeLiveStreamWatermarksRequest.builder()
                    .regionId("<your-region-id>")
                    .domain("<your-domain>")
                    .keyWord("<your-keyword>")
                    // The request-level configuration. You can overwrite HTTP request parameters.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                    .build();
    
            // Asynchronously obtain the return value of the API request.
            CompletableFuture<DescribeLiveStreamWatermarksResponse> response = client.describeLiveStreamWatermarks(describeLiveStreamWatermarksRequest);
            // Synchronously obtain the return value of the API request.
            DescribeLiveStreamWatermarksResponse resp = response.get();
            System.out.println(new Gson().toJson(resp));
            // Asynchronously process the return value.
            /*response.thenAccept(resp -> {
                System.out.println(new Gson().toJson(resp));
            }).exceptionally(throwable -> { // Handle exceptions.
                System.out.println(throwable.getMessage());
                return null;
            });*/
    
            // Close the client.
            client.close();
        }
    
    }
    Note
    • You can query the list of watermark templates by template ID or name. For more information, see the DescribeLiveStreamWatermarks API reference.

    • You can save the queried watermark template information as a template in your business system.

  3. Add a watermark template configuration.

    // This file is auto-generated, don't edit it. Thanks.
    package demo;
    
    import com.aliyun.auth.credentials.Credential;
    import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
    import com.aliyun.core.http.HttpClient;
    import com.aliyun.core.http.HttpMethod;
    import com.aliyun.core.http.ProxyOptions;
    import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
    import com.aliyun.sdk.service.live20161101.models.*;
    import com.aliyun.sdk.service.live20161101.*;
    import com.google.gson.Gson;
    import darabonba.core.RequestConfiguration;
    import darabonba.core.client.ClientOverrideConfiguration;
    import darabonba.core.utils.CommonUtil;
    import darabonba.core.TeaPair;
    
    //import javax.net.ssl.KeyManager;
    //import javax.net.ssl.X509TrustManager;
    import java.net.InetSocketAddress;
    import java.time.Duration;
    import java.util.*;
    import java.util.concurrent.CompletableFuture;
    import java.io.*;
    
    public class AddLiveStreamWatermark {
        public static void main(String[] args) throws Exception {
    
            // Configure the HttpClient.
            /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                    .connectionTimeout(Duration.ofSeconds(10)) // The timeout period for a connection. Default value: 10 seconds.
                    .responseTimeout(Duration.ofSeconds(10)) // The timeout period for a response. Default value: 20 seconds.
                    .maxConnections(128) // The connection pool size.
                    .maxIdleTimeOut(Duration.ofSeconds(50)) // The timeout period for the connection pool. Default value: 30 seconds.
                    // Configure the proxy.
                    .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<your-proxy-hostname>", 9001))
                            .setCredentials("<your-proxy-username>", "<your-proxy-password>"))
                    // For an HTTPS connection, you must configure a certificate or ignore the certificate by using .ignoreSSL(true).
                    .x509TrustManagers(new X509TrustManager[]{})
                    .keyManagers(new KeyManager[]{})
                    .ignoreSSL(false)
                    .build();*/
    
            // Configure the credentials for authentication, including the AccessKey ID, AccessKey secret, and security token.
            StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                    // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                    .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                    .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                    //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use a Security Token Service (STS) token.
                    .build());
    
            // Configure the client.
            AsyncClient client = AsyncClient.builder()
                    .region("<your-region-id>") // The region ID.
                    //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                    .credentialsProvider(provider)
                    //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                    // The client-level configuration. You can overwrite the endpoint and HTTP request parameters.
                    .overrideConfiguration(
                            ClientOverrideConfiguration.create()
                                      // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                    .setEndpointOverride("live.aliyuncs.com")
                            //.setConnectTimeout(Duration.ofSeconds(30))
                    )
                    .build();
    
            // Set the parameters for the API request.
            AddLiveStreamWatermarkRequest addLiveStreamWatermarkRequest = AddLiveStreamWatermarkRequest.builder()
                    .regionId("<your-region-id>")
                    .type(1)
                    .name("<your-name>")
                    .refWidth(1920)
                    .refHeight(1080)
                    .xOffset(50F)
                    .yOffset(100F)
                    .height(200)
                    .transparency(255)
                    .offsetCorner("<your-offset-corner>")
                    .pictureUrl("<your-picture-url>")
                    // The request-level configuration. You can overwrite HTTP request parameters.
                    // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                    .build();
    
            // Asynchronously obtain the return value of the API request.
            CompletableFuture<AddLiveStreamWatermarkResponse> response = client.addLiveStreamWatermark(addLiveStreamWatermarkRequest);
            // Synchronously obtain the return value of the API request.
            AddLiveStreamWatermarkResponse resp = response.get();
            System.out.println(new Gson().toJson(resp));
            // Asynchronously process the return value.
            /*response.thenAccept(resp -> {
                System.out.println(new Gson().toJson(resp));
            }).exceptionally(throwable -> { // Handle exceptions.
                System.out.println(throwable.getMessage());
                return null;
            });*/
    
            // Close the client.
            client.close();
        }
    
    }
    Note

    For more information about the parameters, see the AddLiveStreamWatermark API reference.

    This completes the watermark template configuration. Next, you must configure a watermark rule.

Important
  • Watermarks and time shifting cannot be used at the same time.

Configure a watermark rule

After creating a watermark template, create a watermark rule to apply it.

You can configure a watermark rule in the console or by using an API.

Configure in the console

  1. Log on to the ApsaraVideo Live console.

  2. In the left-side navigation pane, choose Feature Management > Watermarks. On the Watermarks page, click the Watermark Rules tab.

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

  4. Click Add Watermark Rule.

    image

    The following table describes the watermark rule parameters.

    Parameter

    Description

    Rule Name

    The name of the watermark rule. The name can be up to 32 characters long and can contain Chinese characters, letters, digits, and special characters.

    Rule Description

    The description of the watermark rule. The description can be up to 128 characters long and can contain Chinese characters, letters, digits, and special characters.

    AppName

    The name of the application to which the stream belongs. The AppName must be the same as the AppName in the ingest URL for the watermark template to take effect. The name can be up to 256 characters long and can contain digits, letters, hyphens (-), and underscores (_).

    Stream Name

    The name of the live stream. The following rules apply:

    • Enter a specific stream name to match only that stream. Example: liveStreamA.

    • You can use wildcard matching.

      To match all live streams, enter only an asterisk (*).

      You can also perform prefix or suffix matching. The matching items must be enclosed in parentheses (), and multiple items must be separated by vertical bars |. The asterisk (*) wildcard can be used only at the beginning or end of the string. Example: (abc|123)* matches all streams that start with abc or 123. *(t1|t2) matches all streams that end with t1 or t2.

    • The name can be up to 256 characters long and can contain digits, letters, hyphens (-), underscores (_), asterisks (*), and equal signs (=).

    Watermark Templates

    Select a configured watermark template. If no templates are available, create one first. For more information, see Configure a watermark template.

  5. Click save to complete the watermark rule configuration.

    Note

    After you configure the watermark rule, you must restart the stream ingest for the watermark to appear during playback.

Configure by using an API

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class AddLiveStreamWatermarkRule {
    public static void main(String[] args) throws Exception {

        // Configure the HttpClient.
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // The timeout period for a connection. Default value: 10 seconds.
                .responseTimeout(Duration.ofSeconds(10)) // The timeout period for a response. Default value: 20 seconds.
                .maxConnections(128) // The connection pool size.
                .maxIdleTimeOut(Duration.ofSeconds(50)) // The timeout period for the connection pool. Default value: 30 seconds.
                // Configure the proxy.
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<your-proxy-hostname>", 9001))
                        .setCredentials("<your-proxy-username>", "<your-proxy-password>"))
                // For an HTTPS connection, you must configure a certificate or ignore the certificate by using .ignoreSSL(true).
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure the credentials for authentication, including the AccessKey ID, AccessKey secret, and security token.
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use a Security Token Service (STS) token.
                .build());

        // Configure the client.
        AsyncClient client = AsyncClient.builder()
                .region("<your-region-id>") // The region ID.
                //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                // The client-level configuration. You can overwrite the endpoint and HTTP request parameters.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Set the parameters for the API request.
        AddLiveStreamWatermarkRuleRequest addLiveStreamWatermarkRuleRequest = AddLiveStreamWatermarkRuleRequest.builder()
                .regionId("<your-region-id>")
                .name("<your-name>")
                .domain("<your-domain>")
                .app("<your-app>")
                .stream("<your-stream>")
                .templateId("<your-template-id>")
                // The request-level configuration. You can overwrite HTTP request parameters.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously obtain the return value of the API request.
        CompletableFuture<AddLiveStreamWatermarkRuleResponse> response = client.addLiveStreamWatermarkRule(addLiveStreamWatermarkRuleRequest);
        // Synchronously obtain the return value of the API request.
        AddLiveStreamWatermarkRuleResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronously process the return value.
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handling exceptions.
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Close the client.
        client.close();
    }

}
Note
  • The <AppName> can be up to 256 characters long and can contain digits, letters, hyphens (-), and underscores (_). Asterisks (*) are not supported.

  • Watermark rule matching is based on priority. Rules with a specific <StreamName> (not a wildcard *) are matched first.

  • For more information about the parameters, see the AddLiveStreamWatermarkRule API reference.

Use the feature

After configuring the watermark template and rule, start stream ingest and playback to apply the watermark. The following figure shows a watermarked live video.

image

The watermark in this example is a text-based PNG image.

Watermark transparency

The following code shows how to set the watermark transparency:

// The transparency of the watermark. A smaller value indicates higher transparency. Valid values: 0 to 255. Default value: 255.
addLiveStreamWatermarkRequest.setTransparency(255);

For example, setting the transparency to 128 results in the video shown below:

image

Update watermark

Sample code for updating a watermark template

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class UpdateLiveStreamWatermark {
    public static void main(String[] args) throws Exception {

        // Configure the HttpClient.
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. The default is 10 seconds.
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. The default is 20 seconds.
                .maxConnections(128) // Set the connection pool size.
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. The default is 30 seconds.
                // Configure the proxy.
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // For an HTTPS connection, you must configure the certificate or ignore it by using .ignoreSSL(true).
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure credentials, including the AccessKey ID, AccessKey secret, and token.
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use an STS token.
                .build());

        // Configure the client.
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // The region ID.
                //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                // Override the client-level configuration. You can set the endpoint, HTTP request parameters, and more.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Set the parameters for the API request.
        UpdateLiveStreamWatermarkRequest updateLiveStreamWatermarkRequest = UpdateLiveStreamWatermarkRequest.builder()
                .regionId("<Your RegionId>")
                .templateId("<Your templateId>")
                .name("<Your name>")
                .description("<Your description>")
                // Override the request-level configuration. You can set HTTP request parameters and more.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request.
        CompletableFuture<UpdateLiveStreamWatermarkResponse> response = client.updateLiveStreamWatermark(updateLiveStreamWatermarkRequest);
        // Synchronously get the return value of the API request.
        UpdateLiveStreamWatermarkResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronously process the return value.
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handle exceptions.
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Close the client.
        client.close();
    }

}
Note
  • The <regionId> must match the region of the live center associated with the template's domain name. For a list of region IDs, see service endpoint.

  • For more information about the parameters, see the UpdateLiveStreamWatermark API reference.

Sample code for updating a watermark rule

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class UpdateLiveStreamWatermarkRule {
    public static void main(String[] args) throws Exception {

        // Configure the HttpClient.
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. The default is 10 seconds.
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. The default is 20 seconds.
                .maxConnections(128) // Set the connection pool size.
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. The default is 30 seconds.
                // Configure the proxy.
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // For an HTTPS connection, you must configure the certificate or ignore it by using .ignoreSSL(true).
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure credentials, including the AccessKey ID, AccessKey secret, and token.
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use an STS token.
                .build());

        // Configure the client.
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // The region ID.
                //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                // Override the client-level configuration. You can set the endpoint, HTTP request parameters, and more.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Set the parameters for the API request.
        UpdateLiveStreamWatermarkRuleRequest updateLiveStreamWatermarkRuleRequest = UpdateLiveStreamWatermarkRuleRequest.builder()
                .regionId("<Your RegionId>")
                .ruleId("")
                // Override the request-level configuration. You can set HTTP request parameters and more.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request.
        CompletableFuture<UpdateLiveStreamWatermarkRuleResponse> response = client.updateLiveStreamWatermarkRule(updateLiveStreamWatermarkRuleRequest);
        // Synchronously get the return value of the API request.
        UpdateLiveStreamWatermarkRuleResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronously process the return value.
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handle exceptions.
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Close the client.
        client.close();
    }

}
Note
  • The <regionId> must match the region of the live center associated with the template's domain name. For a list of region IDs, see service endpoint.

  • You can update other properties of the rule. For more information, see the UpdateLiveStreamWatermarkRule API reference.

Changes to a watermark template or rule take effect only after you restart stream ingest. To update a watermark during a live stream without restarting, use the dynamic watermark update feature.

Call the DynamicUpdateWaterMarkStreamRule API to perform this update.

Sample code for dynamic watermark update

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class DynamicUpdateWaterMarkStreamRule {
    public static void main(String[] args) throws Exception {

        // Configure the HttpClient.
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. The default is 10 seconds.
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. The default is 20 seconds.
                .maxConnections(128) // Set the connection pool size.
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. The default is 30 seconds.
                // Configure the proxy.
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // For an HTTPS connection, you must configure the certificate or ignore it by using .ignoreSSL(true).
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure credentials, including the AccessKey ID, AccessKey secret, and token.
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use an STS token.
                .build());

        // Configure the client.
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // The region ID.
                //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                // Override the client-level configuration. You can set the endpoint, HTTP request parameters, and more.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Set the parameters for the API request.
        DynamicUpdateWaterMarkStreamRuleRequest dynamicUpdateWaterMarkStreamRuleRequest = DynamicUpdateWaterMarkStreamRuleRequest.builder()
                .regionId("<Your RegionId>")
                .domain("<Your Domain>")
                .app("<Your App>")
                .stream("<Your Stream>")
                .templateId("<Your TemplateId>")
                // Override the request-level configuration. You can set HTTP request parameters and more.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request.
        CompletableFuture<DynamicUpdateWaterMarkStreamRuleResponse> response = client.dynamicUpdateWaterMarkStreamRule(dynamicUpdateWaterMarkStreamRuleRequest);
        // Synchronously get the return value of the API request.
        DynamicUpdateWaterMarkStreamRuleResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronously process the return value.
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handle exceptions.
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Close the client.
        client.close();
    }

}
Important
  • The <TemplateId> can be the ID of a new template or the original template. Calling this method updates the watermark to match the latest configuration of the specified template, including its image, transparency, and position.

  • Currently, dynamic updates are not supported for watermark rules that use fuzzy matching for the stream name.

Delete watermark template

Before deleting a Watermark Templates, delete all associated watermark rules first.

Sample code for deleting a watermark rule

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class DeleteLiveStreamWatermarkRule {
    public static void main(String[] args) throws Exception {

        // Configure the HttpClient.
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. The default is 10 seconds.
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. The default is 20 seconds.
                .maxConnections(128) // Set the connection pool size.
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. The default is 30 seconds.
                // Configure the proxy.
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // For an HTTPS connection, you must configure the certificate or ignore it by using .ignoreSSL(true).
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure credentials, including the AccessKey ID, AccessKey secret, and token.
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use an STS token.
                .build());

        // Configure the client.
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // The region ID.
                //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                // Override the client-level configuration. You can set the endpoint, HTTP request parameters, and more.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Set the parameters for the API request.
        DeleteLiveStreamWatermarkRuleRequest deleteLiveStreamWatermarkRuleRequest = DeleteLiveStreamWatermarkRuleRequest.builder()
                .regionId("<Your RegionId>")
                .domain("<Your Domain>")
                // Override the request-level configuration. You can set HTTP request parameters and more.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request.
        CompletableFuture<DeleteLiveStreamWatermarkRuleResponse> response = client.deleteLiveStreamWatermarkRule(deleteLiveStreamWatermarkRuleRequest);
        // Synchronously get the return value of the API request.
        DeleteLiveStreamWatermarkRuleResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronously process the return value.
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handle exceptions.
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Close the client.
        client.close();
    }

}
Note

You can specify an AppName to delete all of its associated watermark rules. For more information, see the DeleteLiveStreamWatermarkRule API reference.

Sample code for deleting a watermark template

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class DeleteLiveStreamWatermark {
    public static void main(String[] args) throws Exception {

        // Configure the HttpClient.
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout. The default is 10 seconds.
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout. The default is 20 seconds.
                .maxConnections(128) // Set the connection pool size.
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout. The default is 30 seconds.
                // Configure the proxy.
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // For an HTTPS connection, you must configure the certificate or ignore it by using .ignoreSSL(true).
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure credentials, including the AccessKey ID, AccessKey secret, and token.
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // Use an STS token.
                .build());

        // Configure the client.
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // The region ID.
                //.httpClient(httpClient) // Use the configured HttpClient. Otherwise, the default Apache HttpClient is used.
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // The service-level configuration.
                // Override the client-level configuration. You can set the endpoint, HTTP request parameters, and more.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For more information about the endpoint, see https://api.aliyun.com/product/live.
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Set the parameters for the API request.
        DeleteLiveStreamWatermarkRequest deleteLiveStreamWatermarkRequest = DeleteLiveStreamWatermarkRequest.builder()
                .regionId("<Your RegionId>")
                .templateId("<Your TemplateId>")
                // Override the request-level configuration. You can set HTTP request parameters and more.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request.
        CompletableFuture<DeleteLiveStreamWatermarkResponse> response = client.deleteLiveStreamWatermark(deleteLiveStreamWatermarkRequest);
        // Synchronously get the return value of the API request.
        DeleteLiveStreamWatermarkResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronously process the return value.
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handle exceptions.
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Close the client.
        client.close();
    }

}
Note
  • The <regionId> must match the region of the live center associated with the template's domain name. For a list of region IDs, see service endpoint.

  • For more information, see the DeleteLiveStreamWatermark API reference.

References

For information about using the Java SDK, see the Java SDK usage guide.