All Products
Search
Document Center

ApsaraVideo Media Processing:Watermarks

Last Updated:Mar 28, 2026

You can add visible watermarks, such as company logos or TV station logos, to your videos to enhance brand visibility, protect copyrights, and increase product recognition. ApsaraVideo Media Processing (MPS) supports image watermarks, animated watermarks, and text watermarks. This topic provides a code sample that shows how to add watermarks using the MPS SDK for PHP.

Sample code

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // The region where MPS is activated.
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}

try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = submitClipJob($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function submitClipJob($client) {
    $pipelineId = 'd7cedd984be7dd63395c*****';   # The pipeline ID. You can obtain this from the MPS console.
    $templateId = "S00000*01-100020"; # The transcoding template ID. You can obtain this from the MPS console.
    $ossLocation = 'oss-cn-shanghai';
    $bucket = '<bucket name>';
    $ossInputObject = 'input.mp4';
    $ossOutputObject = 'output.mp4';
    # The watermark template ID. You can obtain this from the MPS console. This applies only to image and animated watermarks.
    $watermarkTemplateId = '0ba6fb1ab7c5271a2e1293*****';
    $imageWatermarkObject = 'logo.png';
    $videoWatermarkObject = 'logo.mov';
    $request = new Mts\SubmitJobsRequest();
    # Input parameters
    $input = array('Location' => $ossLocation,
               'Bucket' => $bucket,
               'Object' => urlencode($ossInputObject));

    # Output parameters
    $output = array('OutputObject' => urlencode($ossOutputObject));
    $output['TemplateId'] = $templateId;
    # Image watermark
    $imageWatermarkInput = array(
                            'Location' => $ossLocation,
                            'Bucket' => $bucket,
                            'Object' => urlencode($imageWatermarkObject)
                            );
    $imageWatermark = array(
                    'WaterMarkTemplateId' => $watermarkTemplateId,
                    'Type' => 'Image',
                    'InputFile' => $imageWatermarkInput,
                    'ReferPos' => 'TopRight',
                    'Width' => 0.05,
                    'Dx' => 0,
                    'Dy'=> 0
                    );
    # Text watermark
    $textConfig = array(
                # The 'Content' value must be Base64-encoded.
                'Content' => '5rWL6K+V5paH5a2X5rC05Y2w',
                'FontName' => 'SimSun',
                'FontSize' => 16,
                'FontColor' => 'Red',
                'FontAlpha' => 0.5,
                'Top' => 10,
                'Left' => 10
                );
    $textWatermark = array(
                    'Type' => 'Text',
                    'TextWaterMark' => $textConfig
                    );
    # Animated watermark
    $videoWatermarkInput = array (
                            'Location' => $ossLocation,
                            'Bucket' => $bucket,
                            'Object' => urlencode($videoWatermarkObject)
                            );
    $videoWatermark = array(
                    'WaterMarkTemplateId' => $watermarkTemplateId,
                    'Type' => 'Image',
                    'InputFile'=> $videoWatermarkInput,
                    'ReferPos' => 'BottomLeft',
                    'Height' => 240,
                    'Dx' => 0,
                    'Dy' => 0
                    );
    # An array of watermarks. You can add up to four watermarks.
    $watermarks = array($imageWatermark, $textWatermark, $videoWatermark);
    $output['WaterMarks'] = $watermarks;
    $outputs = array($output);
    # Request parameters
    $request->setInput(json_encode($input));
    $request->setOutputs(json_encode($outputs));
    $request->setOutputBucket($bucket);
    $request->setOutputLocation($ossLocation);
    $request->setPipelineId($pipelineId);
    return $client->getAcsResponse($request);
}

References