Modifying a Watermark Template

Core Code

  1. Create MPC configuration items.
    These configuration items are used for MPC to obtain authorization. Table 1 describes the parameters.
    1
    2
    3
    4
    5
       MpcConfig mpcConfig = new MpcConfig();
           mpcConfig.setEndPoint(endPoint);// Set the endpoint.
           mpcConfig.setProjectId(projectId);// Set the project ID.
           mpcConfig.setSk(sk);// Set the SK.
           mpcConfig.setAk(ak);// Set the AK.
    
    Table 1 MPC parameters

    Parameter

    Type

    Description

    endPoint

    String

    Endpoint. The endpoint of MPC is mts.cn-north-4.myhuaweicloud.com. Replace cn-north-4 with the value of region in the address box of the browser after you select MPC on the management console.

    ProjectId

    String

    Project ID. For details, see Obtaining a Project ID and Account Name.

    ak

    String

    Access key ID (AK). For details, see Obtaining the AK/SK Pair.

    sk

    String

    Secret Access Key (SK) used together with the AK. For details, see Obtaining the AK/SK Pair.

  2. Create an MpcClient instance.

    If no proxy server is configured, you can directly create an MpcClient instance.

    1
    2
         // Create an MpcClient instance.
         MpcClient mpcClient = new MpcClient(mpcConfig);
    

    If a proxy server needs to be configured, set proxy parameters and then transfer the proxy as a constructor to the MpcClient instance.

    1
    2
    3
    4
    5
    6
    7
    8
    // Configure the proxy.
    ClientConfig clientConfig = new ClientConfig();
           clientConfig.setProxyHost(proxyHost);// Set the IP address of the proxy server.
           clientConfig.setProxyPort(Integer.parseInt(proxyPort));// Set the port number of the proxy server.
           clientConfig.setProxyUserName(proxyUserName);// Set the username for accessing the proxy server.
           clientConfig.setProxyPassword(proxyPassword);// Set the password for accessing the proxy server.
    // Use the constructor to initialize MpcClient.
     MpcClient mpcClient =new MpcClient(mpcConfig, clientConfig);
    
  3. Send a request.
    1
    2
            // Set request parameters.
            UpdateWatermarkTemplateRequest updateWatermarkTemplateRequest = new UpdateWatermarkTemplateRequest();
    
  4. Set template parameters.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    // Set the watermark template ID.
            updateWatermarkTemplateRequest.setTemplateId("template_id");
    
            // Set the watermark template name.
            updateWatermarkTemplateRequest.setTemplateName("template_name");
    
           // Set the watermark type.
            updateWatermarkTemplateRequest.setType("Image");
    
           // Set how the image watermark is processed.
            updateWatermarkTemplateRequest.setImageProcess("Original");
    
           // Set the watermark image width.
            updateWatermarkTemplateRequest.setWidth("20");
    
           // Set the watermark image height.
            updateWatermarkTemplateRequest.setHeight("30");
    
           // Set the horizontal offset of the watermark image relative to the output video. The default value is 0.
            updateWatermarkTemplateRequest.setDx("20");
    
           // Set the vertical offset of the watermark image relative to the output video.
            updateWatermarkTemplateRequest.setDy("30");
    
           // Set the watermark position. The options are TopRight, TopLeft, BottomRight, and BottomLeft.
            updateWatermarkTemplateRequest.setReferpos("TopRight");
    
           // Set the watermark start time.
            updateWatermarkTemplateRequest.setTimelineStart("10");
    
           // Set the watermark duration. The default value is ToEND.
            updateWatermarkTemplateRequest.setTimelineDuration("ToEND");
    
  5. Send a request for modifying a watermark template and return a message.
    1
    2
    3
    4
    5
            // Send a request to MPC.
            BaseResponse baseResponse = mpcClient.updateWatermarkTemplate(updateWatermarkTemplateRequest);
    
           // Return a message.
            System.out.println(new Gson().toJson(baseResponse));
    

Full Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Service process:
* 1. Import the SDK package MPCSDK.jar.
* 2. Set configuration items, including the endpoint, AK, SK, and project ID, for accessing MPC and authorization.
* 3. Set request parameters for modifying a watermark template, including the template ID, template name, and watermark type.
* 4. Send a request.
* 5. Return the result.
*/
import com.google.gson.Gson;
import com.huawei.mpc.client.ClientConfig;
import com.huawei.mpc.client.MpcClient;
import com.huawei.mpc.client.MpcConfig;
import com.huawei.mpc.model.BaseResponse;
import com.huawei.mpc.model.watermark.UpdateWatermarkTemplateRequest;
       // Set the method for constructing MPC configuration items.
        MpcConfig mpcConfig = new MpcConfig();

      // Mandatory. Set the endpoint of MPC. For details, see section "Obtaining Key Parameters."
        mpcConfig.setEndPoint(endPoint);

       // Mandatory. Set the user's project ID. For details, see section "Obtaining Key Parameters."
        mpcConfig.setProjectId(projectId);

       // Mandatory. Set the SK. For details, see section "Obtaining Key Parameters."
        mpcConfig.setSk(sk);

       // Mandatory. Set the AK. For details, see section "Obtaining Key Parameters."
        mpcConfig.setAk(ak);
       
       /*if you need proxy*/
      // Optional. Set the proxy if necessary.
       /*
          ClientConfig clientConfig = new ClientConfig();
         // Set the IP address of the proxy server.
           clientConfig.setProxyHost(proxyHost);
         // Set the port number of the proxy server.
            clientConfig.setProxyPort(Integer.parseInt(proxyPort));
          // Set the username for accessing the proxy server.
           clientConfig.setProxyUserName(proxyUserName);
         // Set the password for accessing the proxy server.
          clientConfig.setProxyPassword(proxyPassword);
         */

       // MPC construction method
        MpcClient mpcClient = new MpcClient(mpcConfig);
       // If a proxy needs to be set, use this constructor to initialize MpcClient.
	// MpcClient mpcClient =new MpcClient(mpcConfig, clientConfig);
        
       // Set request parameters.
        UpdateWatermarkTemplateRequest updateWatermarkTemplateRequest = new UpdateWatermarkTemplateRequest();

        // Set the watermark template ID.
        updateWatermarkTemplateRequest.setTemplateId("template_id");

       // Set the watermark template name.
        updateWatermarkTemplateRequest.setTemplateName("template_name");

       // Set the watermark type.
        updateWatermarkTemplateRequest.setType("Image");

       // Set how the image watermark is processed.
        updateWatermarkTemplateRequest.setImageProcess("Original");

       // Set the watermark image width.
        updateWatermarkTemplateRequest.setWidth("20");

       // Set the watermark image height.
        updateWatermarkTemplateRequest.setHeight("30");

       // Set the horizontal offset of the watermark image relative to the output video. The default value is 0.
        updateWatermarkTemplateRequest.setDx("20");

       // Set the vertical offset of the watermark image relative to the output video.
        updateWatermarkTemplateRequest.setDy("30");

       // Set the watermark position. The options are TopRight, TopLeft, BottomRight, and BottomLeft.
        updateWatermarkTemplateRequest.setReferpos("TopRight");

       // Set the watermark start time.
        updateWatermarkTemplateRequest.setTimelineStart("10");

       // Set the watermark duration. The default value is ToEND.
        updateWatermarkTemplateRequest.setTimelineDuration("ToEND");

       // Send a request to MPC.
        BaseResponse baseResponse = mpcClient.updateWatermarkTemplate(updateWatermarkTemplateRequest);

       // Return a message.
        System.out.println(new Gson().toJson(baseResponse));