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.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.AddWatermark
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                AddWatermarkResponse response = AddWatermark(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Adds the watermark configuration.
        /// </summary>
        /// <returns>The watermark.</returns>
        /// <param name="client">The client.</param>
        public static AddWatermarkResponse AddWatermark(DefaultAcsClient client)
        {
            // Constructs a request.
            AddWatermarkRequest request = new AddWatermarkRequest();
            // Sets the watermark name.
            request.Name = "addwatermark";
            // 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).
            request.FileUrl = "http://test-bucket.oss-cn-shanghai.aliyuncs.com/watermark/test.png";

            // Specifies the display position configuration of an image watermark.
            request.WatermarkConfig = BuildImageWatermarkConfig();

            // Specifies the display position configuration of a text watermark.
            request.WatermarkConfig = BuildTextWatermarkConfig();

            // Sets the watermark type. Enter Text for a text watermark or Image for an image watermark.
            request.Type = "Image";

            return client.GetAcsResponse(request);
        }

        /// <summary>
        /// Constructs the configuration of an image watermark. Modify parameters as required.
        /// </summary>
        /// <returns>The image watermark configuration.</returns>
        public static string BuildImageWatermarkConfig()
        {
            JObject watermarkConfig = new JObject();
            // The lateral offset of the watermark.
            watermarkConfig.Add("Dx", "8");
            // The longitudinal offset of the watermark.
            watermarkConfig.Add("Dy", "8");
            // The width of the watermark.
            watermarkConfig.Add("Width", "55");
            // The height of the watermark.
            watermarkConfig.Add("Height", "55");
            // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
            watermarkConfig.Add("ReferPos", "BottomRight");

            // The timeline of watermark display, including the start time and end time.
            JObject timeline = new JObject();
            // The start time for watermark display.
            timeline.Add("Start", "2");
            // The end time for watermark display.
            timeline.Add("Duration", "ToEND");

            watermarkConfig.Add("Timeline", timeline);

            return watermarkConfig.ToString();
        }

        /// <summary>
        /// Constructs the configuration of a text watermark. Modify parameters as required.
        /// </summary>
        /// <returns>The text watermark configuration.</returns>
        public static string BuildTextWatermarkConfig()
        {
            JObject watermarkConfig = new JObject();
            // The content of the text watermark.
            watermarkConfig.Add("Content", "testwatermark");
            // The font of the text watermark.
            watermarkConfig.Add("FontName", "SimSun");
            // The font size of the text watermark.
            watermarkConfig.Add("FontSize", 25);
            // The color or RGB value (such as #000000) of the text watermark.
            watermarkConfig.Add("FontColor", "Black");
            // The transparency of the text watermark.
            watermarkConfig.Add("FontAlpha", "0.2");
            // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
            watermarkConfig.Add("BorderColor", "White");
            // The outline width of the text watermark.
            watermarkConfig.Add("BorderWidth", 1);
            // The offset of the text watermark to the top of the video image.
            watermarkConfig.Add("Top", 20);
            // The offset of the text watermark to the left of the video image.
            watermarkConfig.Add("Left", 15);

            return watermarkConfig.ToString();
        }
    }
}

Modify a watermark

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.UpdateWatermark
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                UpdateWatermarkResponse response = UpdateWatermark(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Modifies the watermark configuration.
        /// </summary>
        /// <returns>The watermark.</returns>
        /// <param name="client">The client.</param>
        public static UpdateWatermarkResponse UpdateWatermark(DefaultAcsClient client)
        {
            // Constructs a request.
            UpdateWatermarkRequest request = new UpdateWatermarkRequest();
            // Sets the watermark name.
            request.Name = "updateWatermark";
            // Specifies the ID of the watermark whose configuration needs to be updated.
            request.WatermarkId = "421ddddd4f6e734a526fd2e442";

            // Specifies the display position configuration of an image watermark.
            request.WatermarkConfig = BuildImageWatermarkConfig();

            // Specifies the display position configuration of a text watermark.
            // request.WatermarkConfig = BuildTextWatermarkConfig();

            return client.GetAcsResponse(request);
        }

        /// <summary>
        /// Constructs the configuration of an image watermark. Modify parameters as required.
        /// </summary>
        /// <returns>The image watermark configuration.</returns>
        public static string BuildImageWatermarkConfig()
        {
            JObject watermarkConfig = new JObject();
            // The lateral offset of the watermark.
            watermarkConfig.Add("Dx", "8");
            // The longitudinal offset of the watermark.
            watermarkConfig.Add("Dy", "8");
            // The width of the watermark.
            watermarkConfig.Add("Width", "55");
            // The height of the watermark.
            watermarkConfig.Add("Height", "55");
            // The relative display position of the watermark, such as the top-left, top-right, bottom-left, or bottom-right corner.
            watermarkConfig.Add("ReferPos", "BottomRight");

            // The timeline of watermark display, including the start time and end time.
            JObject timeline = new JObject();
            // The start time for watermark display.
            timeline.Add("Start", "2");
            // The end time for watermark display.
            timeline.Add("Duration", "ToEND");

            watermarkConfig.Add("Timeline", timeline);

            return watermarkConfig.ToString();
        }

        /// <summary>
        /// Constructs the configuration of a text watermark. Modify parameters as required.
        /// </summary>
        /// <returns>The text watermark configuration.</returns>
        public static string BuildTextWatermarkConfig()
        {
            JObject watermarkConfig = new JObject();
            // The content of the text watermark.
            watermarkConfig.Add("Content", "testwatermark");
            // The font of the text watermark.
            watermarkConfig.Add("FontName", "SimSun");
            // The font size of the text watermark.
            watermarkConfig.Add("FontSize", 25);
            // The color or RGB value (such as #000000) of the text watermark.
            watermarkConfig.Add("FontColor", "Black");
            // The transparency of the text watermark.
            watermarkConfig.Add("FontAlpha", "0.2");
            // The color or RGB value (such as #ffffff) of the font outline for the text watermark.
            watermarkConfig.Add("BorderColor", "White");
            // The outline width of the text watermark.
            watermarkConfig.Add("BorderWidth", 1);
            // The offset of the text watermark to the top of the video image.
            watermarkConfig.Add("Top", 20);
            // The offset of the text watermark to the left of the video image.
            watermarkConfig.Add("Left", 15);

            return watermarkConfig.ToString();
        }
    }
}

Delete a watermark

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteWatermark
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                DeleteWatermarkResponse response = DeleteWatermark(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Deletes the watermark configuration.
        /// </summary>
        /// <returns>The watermark response. </returns>
        /// <param name="client">The client.</param>
        public static DeleteWatermarkResponse DeleteWatermark(DefaultAcsClient client)
        {
            // Constructs a request.
            DeleteWatermarkRequest request = new DeleteWatermarkRequest();
            // Sets the watermark ID.
            request.WatermarkId = "53f9d796fad9d7b862b2e5e5b";
            return client.GetAcsResponse(request);
        }
    }
}

Query a list of watermarks

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.ListWatermark
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                ListWatermarkResponse response = ListWatermark(client);

                if (response.WatermarkInfos ! = null && response.WatermarkInfos.Count > 0)
                {
                    foreach (ListWatermarkResponse.ListWatermark_WatermarkInfo watermarkInfo in response.WatermarkInfos) 
                    {
                        // The watermark ID.
                        Console.WriteLine("WatermarkId = " + watermarkInfo.WatermarkId);
                        // The display position and effect configuration of the watermark.
                        Console.WriteLine("WatermarkConfig = " + watermarkInfo.WatermarkConfig);
                        // The URL of the watermark file. A text watermark has no file URL.
                        Console.WriteLine("FileUrl = " + watermarkInfo.FileUrl);
                    }
                }
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Obtains a list of watermarks.
        /// </summary>
        /// <returns>The watermark list.</returns>
        /// <param name="client">The client.</param>
        public static ListWatermarkResponse ListWatermark(DefaultAcsClient client)
        {
            // Constructs a request.
            ListWatermarkRequest request = new ListWatermarkRequest();

            return client.GetAcsResponse(request);
        }

    }
}

Query a watermark

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetWatermark
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                GetWatermarkResponse response = GetWatermark(client);
                if (response.WatermarkInfo ! = null)
                {
                    // The watermark ID.
                    Console.WriteLine("WatermarkId = " + response.WatermarkInfo.WatermarkId);
                    // The display position and effect configuration of the watermark.
                    Console.WriteLine("WatermarkConfig = " + response.WatermarkInfo.WatermarkConfig);
                    // The URL of the watermark file. A text watermark has no file URL.
                    Console.WriteLine("FileUrl = " + response.WatermarkInfo.FileUrl);
                }
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Queries the configuration of a watermark.
        /// </summary>
        /// <returns>The watermark.</returns>
        /// <param name="client">The client.</param>
        public static GetWatermarkResponse GetWatermark(DefaultAcsClient client)
        {
            // Constructs a request.
            GetWatermarkRequest request = new GetWatermarkRequest();
            // Specifies the ID of the watermark to be queried.
            request.WatermarkId = "96d4f6e734a526fd2e442";
            return client.GetAcsResponse(request);
        }
    }
}

Set the default watermark

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.SetDefaultWatermark
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                SetDefaultWatermarkResponse response = SetDefaultWatermark(client);

                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Sets the default watermark configuration.
        /// </summary>
        /// <returns>The default watermark.</returns>
        /// <param name="client">The client.</param>
        public static SetDefaultWatermarkResponse SetDefaultWatermark(DefaultAcsClient client)
        {
            // Constructs a request.
            SetDefaultWatermarkRequest request = new SetDefaultWatermarkRequest();
            // Sets the ID of the default watermark.
            request.WatermarkId = "82105a29c6e96d4f6e734a";

            return client.GetAcsResponse(request);
        }
    }
}