Tüm Ürünler
Search
Belge Merkezi

ApsaraVideo VOD:Videolar için görüntü ve metin filigranları

Son Güncelleme:Oct 09, 2026

Video filigranlama; şirket logoları, TV kanalı simgeleri, kullanıcı takma adları veya kullanıcı kimlikleri gibi tanımlayıcı bilgileri videolara ekleyerek markanızı öne çıkarmanıza, telif hakkınızı korumanıza ve ürün tanınırlığınızı artırmanıza olanak tanır. Görüntü veya metin filigranları eklemek, değiştirmek, silmek ve sorgulamak için Java SDK örnekleri sunulmuştur.

Kullanım notları

  • Bu konudaki tüm örnekler, bir istemci örneğini başlatmak için AccessKey çifti kullanır.

  • İstek ve yanıt parametrelerinin ayrıntıları için Alibaba Cloud OpenAPI Explorer adresini ziyaret edin ve API Documentations sekmesini açın.

  • Diğer API işlemlerinin SDK örnekleri için Alibaba Cloud OpenAPI Explorer adresini ziyaret edin. Parameters sekmesinde parametreleri belirtin ve çağrıyı başlatın. Ardından kodu görüntülemek ve indirmek için SDK Sample Code sekmesinden SDK sürümünü ve dilini seçin.

  • Bu konudaki örnekler SDK V1.0 kullanır. V2.0 örnekleri için OpenAPI Explorer'da doğru SDK sürümünü seçin.

İstemciyi başlatma

SDK'yı kullanmadan önce bir istemci başlatın. Daha fazla bilgi için bkz. Initialization.

Filigran ekleme

Filigran eklemek için AddWatermark işlemini çağırın. Aşağıdaki örneğe bakın.

OpenAPI Portal: veya AddWatermark.

Not
  • Yükleme URL'si ve kimlik bilgilerini alma parametreleri hakkında daha fazla bilgi için bkz. CreateUploadAttachedMedia.

  • Filigran dosyasını Object Storage Service (OSS) hizmetine yükleme parametreleri hakkında daha fazla bilgi için bkz. Upload OSS objects.

Aşağıdaki kodda bir örnek verilmiştir:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.AddWatermarkRequest;
import com.aliyuncs.vod.model.v20170321.AddWatermarkResponse;

/** 
 * Read the AccessKey information.
 */
public static DefaultAcsClient initVodClient() throws ClientException {
    // The region where ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all the resources in your account may be compromised.
    // This example shows how to obtain the AccessKey pair from environment variables to authenticate API requests. Before you run the example, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

/**
 * The function to add watermark configuration information.
 */
public static AddWatermarkResponse addWatermark(DefaultAcsClient client) throws Exception {
    AddWatermarkRequest request = new AddWatermarkRequest();
    // The name of the watermark.
    request.setName("addwatermark");
    // The OSS URL of the watermark file. Example: http://example.oss-cn-shanghai.aliyuncs.com/watermark/test-****.png.
    String fileUrl = "<your watermarkFile URL>";
    // For an image watermark, you must specify the OSS URL of the image file. The watermark file must be in the same region as the video. For example, if the video is in the China (Shanghai) region, the watermark file must also be stored in the China (Shanghai) region.
    request.setFileUrl(fileUrl);
    // The watermark configuration data.
    JSONObject watermarkConfig = null;
    // The position configuration data for the image watermark.
    watermarkConfig = buildImageWatermarkConfig();

    // The position configuration data for the text watermark.
    //watermarkConfig = buildTextWatermarkConfig();
    request.setWatermarkConfig(watermarkConfig.toJSONString());

    // Text watermark: Text. Image watermark: Image.
    request.setType("Image");
    return client.getAcsResponse(request);
}

/**
 * The following code provides an example.
 * @param args
 * @throws ClientException
 */
public static void main(String[] args) throws ClientException {
    DefaultAcsClient client = initVodClient();
    AddWatermarkResponse response = new AddWatermarkResponse();
    try {
        // Add watermark information.
        response = addWatermark(client);
        // The watermark ID.
        System.out.println("WatermarkId = " + response.getWatermarkInfo().getWatermarkId());
        // The position and effect configuration data of the watermark.
        System.out.println("WatermarkConfig = " + response.getWatermarkInfo().getWatermarkConfig());
        // The FileUrl of the watermark file. This field is empty for text watermarks.
        System.out.println("FileUrl = " + response.getWatermarkInfo().getFileUrl());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

/**
 * Build the configuration data for the image watermark. Modify the parameter values as needed.
 * @return
 */
public static JSONObject buildImageWatermarkConfig() {
    JSONObject watermarkConfig = new JSONObject();
    // The horizontal offset of the watermark.
    watermarkConfig.put("Dx", "8");
    // The vertical offset of the watermark.
    watermarkConfig.put("Dy", "8");
    // The width of the watermark.
    watermarkConfig.put("Width", "55");
    // The height of the watermark.
    watermarkConfig.put("Height", "55");
    // The relative position of the watermark. Valid values: TopLeft, TopRight, BottomLeft, and BottomRight.
    watermarkConfig.put("ReferPos", "BottomRight");
    // The timeline for displaying the watermark. You can specify the start time and end time.
    JSONObject timeline = new JSONObject();
    // The start time for displaying the watermark.
    timeline.put("Start", "2");
    // The end time for displaying the watermark.
    timeline.put("Duration", "ToEND");
    watermarkConfig.put("Timeline", timeline);
    return watermarkConfig;
}

/**
 * Build the configuration data for the text watermark. Modify the parameter values as needed.
 * @return
 */
public static JSONObject buildTextWatermarkConfig() {
    JSONObject watermarkConfig = new JSONObject();
    // The content of the text watermark.
    watermarkConfig.put("Content", "testwatermark");
    // The font name of the text watermark.
    watermarkConfig.put("FontName", "SimSun");
    // The font size of the text watermark.
    watermarkConfig.put("FontSize", 25);
    // The font color of the text watermark. You can also specify an RGB color value, such as #000000.
    watermarkConfig.put("FontColor", "Black");
    // The transparency of the text watermark.
    watermarkConfig.put("FontAlpha", "0.2");
    // The outline color of the text watermark. You can also specify an RGB color value, such as #ffffff.
    watermarkConfig.put("BorderColor", "White");
    // The outline width of the text watermark.
    watermarkConfig.put("BorderWidth", 1);
    // The offset of the text watermark from the top of the video.
    watermarkConfig.put("Top", 20);
    // The offset of the text watermark from the left of the video.
    watermarkConfig.put("Left", 15);
    return watermarkConfig;
}

Filigranı değiştirme

Bir filigranı değiştirmek için UpdateWatermark işlemini çağırın. Aşağıdaki örneğe bakın.

OpenAPI Portal: | UpdateWatermark.

Aşağıdaki kodda bir örnek verilmiştir:

import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.vod.model.v20170321.UpdateWatermarkRequest;
import com.aliyuncs.vod.model.v20170321.UpdateWatermarkResponse;

/** 
 * Read the AccessKey information.
 */
public static DefaultAcsClient initVodClient() throws ClientException {
    // The region where ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all the resources in your account may be compromised.
    // This example shows how to obtain the AccessKey pair from environment variables to authenticate API requests. Before you run the example, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

/**
 * The function to modify watermark configuration information.
 * Note: You cannot modify the file URL of an image watermark. To use a different image, create a new watermark.
 */
public static UpdateWatermarkResponse updateWatermark(DefaultAcsClient client) throws Exception {
    UpdateWatermarkRequest request = new UpdateWatermarkRequest();
    request.setName("updatewatermark");
    // The ID of the watermark whose configuration information you want to update.
    request.setWatermarkId("421ddddd4f6e734a526fd2****");
    // The watermark configuration data.
    JSONObject watermarkConfig = null;
    // The position configuration data for the image watermark.
    //watermarkConfig = buildImageWatermarkConfig();
    // The position configuration data for the text watermark.
    watermarkConfig = buildTextWatermarkConfig();
    request.setWatermarkConfig(watermarkConfig.toJSONString());
    return client.getAcsResponse(request);
}

/**
 * The following code provides an example.
 */
public static void main(String[] args) {
    DefaultAcsClient client = initVodClient();
    UpdateWatermarkResponse response = new UpdateWatermarkResponse();
    try {
        response = updateWatermark(client);
        // The watermark ID.
        System.out.println("WatermarkId = " + response.getWatermarkInfo().getWatermarkId());
        // The position and effect configuration data of the watermark.
        System.out.println("WatermarkConfig = " + response.getWatermarkInfo().getWatermarkConfig());
        // The FileUrl of the watermark file. This field is empty for text watermarks.
        System.out.println("FileUrl = " + response.getWatermarkInfo().getFileUrl());
    } catch (Exception e) {
        System.out.println("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.println("RequestId = " + response.getRequestId());
}

/**
 * Build the configuration data for the image watermark. Modify the parameter values as needed.
 * @return
 */
public static JSONObject buildImageWatermarkConfig() {
    JSONObject watermarkConfig = new JSONObject();
    // The horizontal offset of the watermark.
    watermarkConfig.put("Dx", "10");
    // The vertical offset of the watermark.
    watermarkConfig.put("Dy", "10");
    // The width of the watermark.
    watermarkConfig.put("Width", "66");
    // The height of the watermark.
    watermarkConfig.put("Height", "66");
    // The relative position of the watermark. Valid values: TopLeft, TopRight, BottomLeft, and BottomRight.
    watermarkConfig.put("ReferPos", "BottomLeft");
    // The timeline for displaying the watermark. You can specify the start time and end time.
    JSONObject timeline = new JSONObject();
    // The start time for displaying the watermark.
    timeline.put("Start", "2");
    // The end time for displaying the watermark.
    timeline.put("Duration", "ToEND");
    watermarkConfig.put("Timeline", timeline);
    return watermarkConfig;
}

/**
 * Build the configuration data for the text watermark. Modify the parameter values as needed.
 * @return
 */
public static JSONObject buildTextWatermarkConfig() {
    JSONObject watermarkConfig = new JSONObject();
    // The content of the text watermark.
    watermarkConfig.put("Content", "testwatermark");
    // The font name of the text watermark.
    watermarkConfig.put("FontName", "SimSun");
    // The font size of the text watermark.
    watermarkConfig.put("FontSize", 40);
    // The font color of the text watermark. You can also specify an RGB color value, such as #000000.
    watermarkConfig.put("FontColor", "Black");
    // The transparency of the text watermark.
    watermarkConfig.put("FontAlpha", "0.2");
    // The outline color of the text watermark. You can also specify an RGB color value, such as #ffffff.
    watermarkConfig.put("BorderColor", "White");
    // The outline width of the text watermark.
    watermarkConfig.put("BorderWidth", 2);
    // The offset of the text watermark from the top of the video.
    watermarkConfig.put("Top", 20);
    // The offset of the text watermark from the left of the video.
    watermarkConfig.put("Left", 15);
    return watermarkConfig;
}

Filigran silme

Bir filigranı silmek için DeleteWatermark işlemini çağırın.

OpenAPI Portal: / DeleteWatermark.

Filigran listesini sorgulama

Filigranları sorgulamak için ListWatermark işlemini çağırın.

OpenAPI Portal: ListWatermark.

Tek bir filigranı sorgulama

Tek bir filigranı sorgulamak için GetWatermark işlemini çağırın.

OpenAPI Portal: GetWatermark.

Varsayılan filigran ayarlama

Varsayılan bir filigran ayarlamak için SetDefaultWatermark işlemini çağırın.

OpenAPI Portal: SetDefaultWatermark.

Başvurular

Videolar için görüntü ve metin filigranları: ApsaraVideo VOD'un görüntü ve metin filigranı özelliği hakkında çalışma mekanizması, kullanım senaryoları ve örnekler dahil olmak üzere ayrıntılı bilgiler sunar.