拼接-开板和尾板

在视频制作中,可以将含有关键信息的视频起始、结尾内容以画中画的形式拼接嵌入到正片视频中,称为开板、尾板。本文为您介绍媒体处理中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);
}