本文提供PHP SDK使用拼接和简单剪辑相关功能的API调用示例。
完整代码
<?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 = submitClipJob($client);
print_r($response);
} catch (Exception $e) {
print $e->getMessage()."\n";
}
function submitClipJob($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;
# 拼接参数
$mergeVideo = array('MergeURL' => 'http://'.$bucket.'.'.$ossLocation.'.aliyuncs.com/'.urlencode($ossInputObject));
$mergeTail = array('MergeURL' => 'http://'.$bucket.'.'.$ossLocation.'.aliyuncs.com/'.urlencode($tailObject));
$output['MergeList'] = array($mergeVideo, $mergeTail);
$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);
}