Adicione marcas d'água visíveis, como logotipos de empresas ou emissoras de TV, aos seus vídeos para aumentar a visibilidade da marca, proteger direitos autorais e melhorar o reconhecimento do produto. O ApsaraVideo Media Processing (MPS) oferece suporte a image watermarks, animated watermarks e text watermarks. Este tópico apresenta um exemplo de código para adicionar marcas d'água com o MPS SDK for PHP.
Código de exemplo
<?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);
}