在視頻制作中,可以將含有關鍵信息的視頻起始、結尾內容以畫中畫的形式拼接嵌入到正片視頻中,稱為開板、尾板。本文為您介紹媒體處理中PHP SDK設置開板和尾板的示例代碼。
完整代碼
<?php
require_once './aliyun-php-sdk-core/Config.php';
use Mts\Request\V20140618 as Mts;
function initMtsClient($accessKeyId, $accessKeySecret) {
$regionId = 'cn-shanghai'; // 服務接入區域
$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 = submitOpenJob($client);
print_r($response);
} catch (Exception $e) {
print $e->getMessage()."\n";
}
function submitOpenJob($client) {
$pipelineId = 'd7cedd984be7dd63395c*****'; #管道ID 可在控制臺查看
$templateId = "S00000001-100020"; #轉碼模板ID,可在控制臺查看
$ossLocation = 'oss-cn-shanghai';
$bucket = '<bucket name>';
$ossInputObject = 'input.mp4';
$ossOutputObject = 'output.mp4';
$headObject = 'head.mp4';
$tailObject = 'tail.mp4';
$request = new Mts\SubmitJobsRequest();
# input參數
$input = array('Location' => $ossLocation,
'Bucket' => $bucket,
'Object' => urlencode($ossInputObject));
# output參數
$output = array('OutputObject' => urlencode($ossOutputObject));
$output['Video'] = array('Width' => 1280,
'Height' => 720);
$output['TemplateId'] = $templateId;
# 開板視頻
$openingVideo = array('OpenUrl' => 'http://'.$bucket.'.'.$ossLocation.'.aliyuncs.com/'.urlencode($headObject),
'Width' => 640,
'Start' => 2);
$output['OpeningList'] = array($openingVideo);
# 尾板視頻
$tailslateVideo = array('TailUrl' => 'http://'.$bucket.'.'.$ossLocation.'.aliyuncs.com/'.urlencode($tailObject),
'Width' => 640,
'BlendDuration' => 3,
'BgColor' => 'Black');
$output['TailSlateList'] = array($tailslateVideo);
$outputs = array($output);
$request->setInput(json_encode($input));
$request->setOUtputs(json_encode($outputs));
$request->setOutputBucket($bucket);
$request->setOutputLocation($ossLocation);
$request->setPipelineId($pipelineId);
return $client->getAcsResponse($request);
}
文檔內容是否對您有幫助?