All Products
Search
Document Center

Watermark

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Add a watermark

For more information about the request and response parameters, see AddWatermark.

  • For more information about how to obtain the upload URL and credential for a file, see CreateUploadAttachedMedia.
  • For more information about how to upload a watermark file to Object Storage Service (OSS), see OSS upload.
#include <stdio.h> 
#include <string>
#include <map>
#include <jsoncpp/json/json.h> 
#include "vod_sdk/openApiUtil.h"

/**
 * Method for constructing the configuration of an image watermark. Modify parameters as required.
 */
Json::Value buildImageWatermarkConfig() {
    Json::Value watermarkConfig;
    // The lateral offset of the watermark.
    watermarkConfig["Dx"] = "8";
    // The longitudinal offset of the watermark.
    watermarkConfig["Dy"] = "8";
    // The width of the watermark.
    watermarkConfig["Width"] = "55";
    // The height of the watermark.
    watermarkConfig["Height"] = "55";
    // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
    watermarkConfig["ReferPos"] = "BottomRight";
    // The timeline of watermark display, including the start time and end time.
    Json::Value timeline;
    // The start time for watermark display.
    timeline["Start"] = "2";
    // The end time for watermark display.
    timeline["Duration"] = "ToEND";
    watermarkConfig["Timeline"] = timeline;
    return watermarkConfig;
}

/**
 * Method for constructing the configuration of a text watermark. Modify parameters as required.
 */
Json::Value buildTextWatermarkConfig() {
    Json::Value watermarkConfig;
    // The content of the text watermark.
    watermarkConfig["Content"] = "testwatermark";
    // The font of the text watermark.
    watermarkConfig["FontName"] = "SimSun";
    // The font size of the text watermark.
    watermarkConfig["FontSize"] = "25";
    // The color or RGB value (such as #000000) of the text watermark.
    watermarkConfig["FontColor"] = "Black";
    // The transparency of the text watermark.
    watermarkConfig["FontAlpha"] = "0.2";
    // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
    watermarkConfig["BorderColor"] = "White";
    // The outline width of the text watermark.
    watermarkConfig["BorderWidth"] = "1";
    // The offset of the text watermark to the top of the video image.
    watermarkConfig["Top"] = "20";
    // The offset of the text watermark to the left of the video image.
    watermarkConfig["Left"] = "15";
    return watermarkConfig;
}

/**
 * Method for adding the watermark configuration
 */
VodApiResponse addWatermark(VodCredential authInfo) {
    string apiName = "AddWatermark";
    map<string, string> args;
    // Sets the watermark name.
    args["Name"] = "testaddwatermark";
    // Obtains the OSS URL of the watermark file.
    string fileUrl = "http://test-bucket.oss-cn-shanghai.aliyuncs.com/watermark/test.png";
    // The OSS URL must be specified for an image watermark file. This watermark file must be stored in the same region as the relevant video. For example, if a video is stored in China (Shanghai), its watermark file must also be stored in China (Shanghai).
    args["FileUrl"] = fileUrl;
    // Specifies the watermark configuration.
    Json::Value watermarkConfig;
    // Specifies the display position configuration of an image watermark.
    watermarkConfig = buildImageWatermarkConfig();
    // Specifies the display position configuration of a text watermark.
    //watermarkConfig = buildTextWatermarkConfig();
    args["WatermarkConfig"] = watermarkConfig.toStyledString();
    // Sets the watermark type. Enter Text for a text watermark or Image for an image watermark.
    args["Type"] = "Image";
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = addWatermark(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Modify a watermark

For more information about the request and response parameters, see UpdateWatermark.

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * Method for constructing the configuration of an image watermark. Modify parameters as required.
 */
Json::Value buildImageWatermarkConfig() {
    Json::Value watermarkConfig;
    // The lateral offset of the watermark.
    watermarkConfig["Dx"] = "8";
    // The longitudinal offset of the watermark.
    watermarkConfig["Dy"] = "8";
    // The width of the watermark.
    watermarkConfig["Width"] = "55";
    // The height of the watermark.
    watermarkConfig["Height"] = "55";
    // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
    watermarkConfig["ReferPos"] = "BottomRight";
    // The timeline of watermark display, including the start time and end time.
    Json::Value timeline;
    // The start time for watermark display.
    timeline["Start"] = "2";
    // The end time for watermark display.
    timeline["Duration"] = "ToEND";
    watermarkConfig["Timeline"] = timeline;
    return watermarkConfig;
}

/**
 * Method for constructing the configuration of a text watermark. Modify parameters as required.
 */
Json::Value buildTextWatermarkConfig() {
    Json::Value watermarkConfig;
    // The content of the text watermark.
    watermarkConfig["Content"] = "testwatermark";
    // The font of the text watermark.
    watermarkConfig["FontName"] = "SimSun";
    // The font size of the text watermark.
    watermarkConfig["FontSize"] = "25";
    // The color or RGB value (such as #000000) of the text watermark.
    watermarkConfig["FontColor"] = "Black";
    // The transparency of the text watermark.
    watermarkConfig["FontAlpha"] = "0.2";
    // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
    watermarkConfig["BorderColor"] = "White";
    // The outline width of the text watermark.
    watermarkConfig["BorderWidth"] = "1";
    // The offset of the text watermark to the top of the video image.
    watermarkConfig["Top"] = "20";
    // The offset of the text watermark to the left of the video image.
    watermarkConfig["Left"] = "15";
    return watermarkConfig;
}

/**
 * Method for modifying the watermark configuration
 * Note: The URL of an image watermark file cannot be directly modified. If you want to modify the URL, you need to create watermark information again and set the new URL in the information.
 */
VodApiResponse updateWatermark(VodCredential authInfo) {
    string apiName = "UpdateWatermark";
    map<string, string> args;
    // Specifies the ID of the watermark whose configuration needs to be updated.
    args["WatermarkId"] = "421ddddd4f6e734a526fd2e442";
    // Specifies the watermark configuration.
    // Specifies the watermark configuration.
    Json::Value watermarkConfig;
    // Specifies the display position configuration of an image watermark.
    watermarkConfig = buildImageWatermarkConfig();
    // Specifies the display position configuration of a text watermark.
    //watermarkConfig = buildTextWatermarkConfig();
    args["WatermarkConfig"] = watermarkConfig.toStyledString();
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = updateWatermark(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Delete a watermark

For more information about the request and response parameters, see DeleteWatermark.

#include <stdio.h> 
#include <string>
#include <map>
#include <jsoncpp/json/json.h> 
#include "vod_sdk/openApiUtil.h"

/**
 * Method for deleting the watermark configuration
 */
VodApiResponse deleteWatermark(VodCredential authInfo) {
    string apiName = "DeleteWatermark";
    map<string, string> args;
    args["WatermarkId"] = "53f9d796fad9d7b862b2e5e5b";
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = deleteWatermark(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Query a list of watermarks

For more information about the request and response parameters, see ListWatermark.

#include <stdio.h> 
#include <string>
#include <map>
#include <jsoncpp/json/json.h> 
#include "vod_sdk/openApiUtil.h"

/**
 * Method for querying the configuration of watermarks
 */
VodApiResponse listWatermark(VodCredential authInfo) {
    string apiName = "ListWatermark";
    map<string, string> args;
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = listWatermark(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Query a watermark

For more information about the request and response parameters, see GetWatermark.

#include <stdio.h> 
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * Method for querying the configuration of a watermark
 */
VodApiResponse getWatermark(VodCredential authInfo) {
    string apiName = "GetWatermark";
    map<string, string> args;
    args["WatermarkId"] = "96d4f6e734a526fd2e442";
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = getWatermark(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Set the default watermark

For more information about the request and response parameters, see SetDefaultWatermark.

#include <stdio.h> 
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * Method for setting the default watermark configuration
 */
VodApiResponse setDefaultWatermark(VodCredential authInfo) {
    string apiName = "SetDefaultWatermark";
    map<string, string> args;
    args["WatermarkId"] = "96d4f6e734a526fd2e442";
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = setDefaultWatermark(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}