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.
// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

// Specifies the display position configuration of an image watermark.
var watermarkConfig = {
    Dx: '8', // The lateral offset of the watermark.
    Dy: '8', // The longitudinal offset of the watermark.
    Width: '55', // The width of the watermark.
    Height: '55', // The height of the watermark.
    ReferPos: 'BottomRight', // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
    // The timeline of watermark display, including the start time and end time.
    Timeline: {
        Start: '2', // The start time for watermark display.
        Duration: 'ToEND' // The end time for watermark display.
    }
};
// Specifies the display position configuration of a text watermark.
// var watermarkConfig = {
//     Content: 'testwatermark', // The content of the text watermark.
//     FontName: 'SimSun', // The font of the text watermark.
//     FontSize: 25, // The font size of the text watermark.
//     FontColor: 'Black', // The color or RGB value (such as #000000) of the text watermark.
//     FontAlpha: '0.2', // The transparency of the text watermark.
//     BorderColor: 'White', // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
//     BorderWidth: 1, // The outline width of the text watermark.
//     Top: 20, // The offset of the text watermark to the top of the video image.
//     Left: 15 // The offset of the text watermark to the left of the video image.
// };

client.request("AddWatermark", {
    Name: 'addwatermark', // Sets the watermark name.
    // Obtains the OSS URL of the watermark file. 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).
    FileUrl: 'http://test-bucket.oss-cn-shanghai.aliyuncs.com/watermark/test.png',
    WatermarkConfig: JSON.stringify(watermarkConfig),
    Type: 'Image'
}, {}).then(function (response) {
    if (response.WatermarkInfo){
        // The watermark ID.
        console.log('WatermarkId = ' + response.WatermarkInfo.WatermarkId);
        // The display position and effect configuration of the watermark.
        console.log('WatermarkConfig = ' + response.WatermarkInfo.WatermarkConfig);
        // The URL of the watermark file. A text watermark has no file URL.
        console.log('FileUrl = ' + response.WatermarkInfo.FileUrl);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Modify a watermark

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

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

// Specifies the display position configuration of an image watermark.
var watermarkConfig = {
    Dx: '8', // The lateral offset of the watermark.
    Dy: '8', // The longitudinal offset of the watermark.
    Width: '55', // The width of the watermark.
    Height: '55', // The height of the watermark.
    ReferPos: 'BottomRight', // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
    // The timeline of watermark display, including the start time and end time.
    Timeline: {
        Start: '2', // The start time for watermark display.
        Duration: 'ToEND' // The end time for watermark display.
    }
};
// Specifies the display position configuration of a text watermark.
// var watermarkConfig = {
//     Content: 'testwatermark', // The content of the text watermark.
//     FontName: 'SimSun', // The font of the text watermark.
//     FontSize: 25, // The font size of the text watermark.
//     FontColor: 'Black', // The color or RGB value (such as #000000) of the text watermark.
//     FontAlpha: '0.2', // The transparency of the text watermark.
//     BorderColor: 'White', // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
//     BorderWidth: 1, // The outline width of the text watermark.
//     Top: 20, // The offset of the text watermark to the top of the video image.
//     Left: 15 // The offset of the text watermark to the left of the video image.
// };

client.request("UpdateWatermark", {
    WatermarkId: 'WatermarkId',
    Name: 'updatewatermark', // Sets the watermark name.
    WatermarkConfig: JSON.stringify(watermarkConfig)
}, {}).then(function (response) {
    if (response.WatermarkInfo){
        // The watermark ID.
        console.log('WatermarkId = ' + response.WatermarkInfo.WatermarkId);
        // The display position and effect configuration of the watermark.
        console.log('WatermarkConfig = ' + response.WatermarkInfo.WatermarkConfig);
        // The URL of the watermark file. A text watermark has no file URL.
        console.log('FileUrl = ' + response.WatermarkInfo.FileUrl);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Delete a watermark

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

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DeleteWatermark", {
    WatermarkId: 'WatermarkId'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query a list of watermarks

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

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("ListWatermark", {}, {}).then(function (response) {
    if (response.WatermarkInfos && response.WatermarkInfos.length > 0){ 
        for (var i=0; i<response.WatermarkInfos.length; i++){ 
            // The watermark ID.
            console.log('WatermarkId = ' + response.WatermarkInfos[i].WatermarkId);
            // The display position and effect configuration of the watermark.
            console.log('WatermarkConfig = ' + response.WatermarkInfos[i].WatermarkConfig);
            // The URL of the watermark file. A text watermark has no file URL.
            console.log('FileUrl = ' + response.WatermarkInfos[i].FileUrl);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query a watermark

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

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("GetWatermark", {
    WatermarkId: 'WatermarkId'
}, {}).then(function (response) {
    if (response.WatermarkInfo){
        // The watermark ID.
        console.log('WatermarkId = ' + response.WatermarkInfo.WatermarkId);
        // The display position and effect configuration of the watermark.
        console.log('WatermarkConfig = ' + response.WatermarkInfo.WatermarkConfig);
        // The URL of the watermark file. A text watermark has no file URL.
        console.log('FileUrl = ' + response.WatermarkInfo.FileUrl);
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Set the default watermark

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

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("SetDefaultWatermark", {
    WatermarkId: 'WatermarkId'
}, {}).then(function (response) {
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});