Cette rubrique présente un exemple de code complet illustrant l'utilisation du SDK ApsaraVideo Media Processing (MPS) pour PHP afin de définir les génériques de début et de fin lors du montage vidéo.
Exemple de code
<?php
require_once './aliyun-php-sdk-core/Config.php';
use Mts\Request\V20140618 as Mts;
function initMtsClient($accessKeyId, $accessKeySecret) {
$regionId = 'cn-shanghai'; // The ID of the region in which your MPS service is deployed.
$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*****'; # The ID of the MPS queue. You can log on to the MPS console to view the ID.
$templateId = "S00000001-100020"; # The ID of the transcoding template. You can log on to the MPS console to view the ID.
$ossLocation = 'oss-cn-shanghai';
$bucket = '<bucket name>';
$ossInputObject = 'input.mp4';
$ossOutputObject = 'output.mp4';
$headObject = 'head.mp4';
$tailObject = 'tail.mp4';
$request = new Mts\SubmitJobsRequest();
# The job input.
$input = array('Location' => $ossLocation,
'Bucket' => $bucket,
'Object' => urlencode($ossInputObject));
# The job output.
$output = array('OutputObject' => urlencode($ossOutputObject));
$output['Video'] = array('Width' => 1280,
'Height' => 720);
$output['TemplateId'] = $templateId;
# Set the opening part.
$openingVideo = array('OpenUrl' => 'http://'.$bucket.'.'.$ossLocation.'.aliyuncs.com/'.urlencode($headObject),
'Width' => 640,
'Start' => 2);
$output['OpeningList'] = array($openingVideo);
# Set the ending part.
$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);
}