Creating a Watermark Template
A watermark template is used to add watermarks to transcoded videos. For details, see Creating a Watermark Template.
Core Code
- 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. For details, see Obtaining an Endpoint.
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.
- 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);
- Send a request.
1
CreateWatermarkTemplateRequest createWatermarkTemplateRequest = new CreateWatermarkTemplateRequest();
- 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
// Set the watermark template name. createWatermarkTemplateRequest.setTemplateName("template_name"); // Set the watermark type. createWatermarkTemplateRequest.setType("Image"); // Set how the image watermark is processed. createWatermarkTemplateRequest.setImageProcess("Original"); // Set the watermark image width. createWatermarkTemplateRequest.setWidth("20"); // Set the watermark image height. createWatermarkTemplateRequest.setHeight("30"); // Set the horizontal offset of the watermark image relative to the output video. The default value is 0. createWatermarkTemplateRequest.setDx("20"); // Set the vertical offset of the watermark image relative to the output video. createWatermarkTemplateRequest.setDy("30"); // Set the watermark position. The options are TopRight, TopLeft, BottomRight, and BottomLeft. createWatermarkTemplateRequest.setReferpos("TopRight"); // Set the watermark start time. createWatermarkTemplateRequest.setTimelineStart("10"); // Set the watermark duration. The default value is ToEND. createWatermarkTemplateRequest.setTimelineDuration("ToEND");
- Send a request for creating a watermark template and return a message.
1 2 3 4 5
// Send a request to MPC. CreateWatermarkTemplateRespons createWatermarkTemplateRespons = mpcClient.createWatermarkTemplate(createWatermarkTemplateRequest); // Return a message. System.out.println(new Gson().toJson(createWatermarkTemplateRespons));
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 |
/*
* 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 creating a watermark template, including the watermark 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.watermark.CreateWatermarkTemplateRequest;
import com.huawei.mpc.model.watermark.CreateWatermarkTemplateRespons;
// 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.
CreateWatermarkTemplateRequest createWatermarkTemplateRequest = new CreateWatermarkTemplateRequest();
// Set the watermark template name.
createWatermarkTemplateRequest.setTemplateName("template_name");
// Set the watermark type.
createWatermarkTemplateRequest.setType("Image");
// Set how the image watermark is processed.
createWatermarkTemplateRequest.setImageProcess("Original");
// Set the watermark image width.
createWatermarkTemplateRequest.setWidth("20");
// Set the watermark image height.
createWatermarkTemplateRequest.setHeight("30");
// Set the horizontal offset of the watermark image relative to the output video. The default value is 0.
createWatermarkTemplateRequest.setDx("20");
// Set the vertical offset of the watermark image relative to the output video.
createWatermarkTemplateRequest.setDy("30");
// Set the watermark position. The options are TopRight, TopLeft, BottomRight, and BottomLeft.
createWatermarkTemplateRequest.setReferpos("TopRight");
// Set the watermark start time.
createWatermarkTemplateRequest.setTimelineStart("10");
// Set the watermark duration. The default value is ToEND.
createWatermarkTemplateRequest.setTimelineDuration("ToEND");
// Send a request to MPC.
CreateWatermarkTemplateRespons createWatermarkTemplateRespons = mpcClient.createWatermarkTemplate(createWatermarkTemplateRequest);
// Return a message.
System.out.println(new Gson().toJson(createWatermarkTemplateRespons));
|
Last Article: Watermarking
Next Article: Modifying a Watermark Template
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.