拼接是把多個不同格式 、不同編碼、分辨率的視頻拼接在一起,輸出成一個格式、編碼、分辨率相同的新視頻。常用于添加固定的片頭和片尾、直播錄制視頻拼接。剪輯是指裁剪視頻的某一段,輸出成一個新視頻。常用于截取視頻中精彩或關鍵的內容。本文提供了媒體處理PHP SDK視頻拼接和簡單剪輯相關功能的API調用示例。
前提條件
視頻拼接和簡單剪輯
調用SubmitJobs對視頻進行拼接和簡單剪輯,接口參數和返回字段詳細信息請參見提交轉碼作業,調用示例如下:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use AlibabaCloud\Darabonba\Env\Env;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SubmitJobsRequest;
class Sample {
private $pipelineId = "<PipelineId>";
private $templateId = "S00000001-100020"; #轉碼模板ID,按需配置
private $ossLocation = "<OssLocation>";
private $bucket = "<bucket name>";
private $oss_input_object = "input.mp4";
private $oss_output_object = "output.mp4";
private $head_object = "head.mp4";
private $tail_object = "tail.mp4";
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* 正式環境下 建議 protocol = "HTTPS";
*/
public static function createClient($accessKeyId, $accessKeySecret, $regionId){
$config = new Config([]);
$config->accessKeyId = $accessKeyId;
$config->accessKeySecret = $accessKeySecret;
$config->regionId = $regionId;
$config->protocol = "HTTP";
return new Mts($config);
}
/**
* @return void
*/
public static function main(){
$sample = new Sample;
$client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
$request = new SubmitJobsRequest([
"input" => json_encode(array(
'Location' => $sample->ossLocation,
'Bucket' => $sample->bucket,
'Object' => urlencode($sample->head_object))
),
"outputBucket" => $sample->bucket,
"outputLocation" => $sample->ossLocation,
"pipelineId" => $sample->pipelineId,
"outputs" => $sample->outputs(),
]);
$response = $client->submitJobs($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
function outputs() {
$output = array('OutputObject' => urlencode($this->oss_output_object));
$output['Video'] = array('Width' => 1280,
'Height' => 720);
$output['TemplateId'] = $this->templateId;
//拼接參數
$merge_video = array('MergeURL' => 'http://'.$this->bucket.'.'.$this->ossLocation.'.aliyuncs.com/'.urlencode($this->oss_input_object));
$merge_tail = array('MergeURL' => 'http://'.$this->bucket.'.'.$this->ossLocation.'.aliyuncs.com/'.urlencode($this->tail_object));
$output['MergeList'] = array($merge_video, $merge_tail);
$outputs = array($output);
return json_encode($outputs);
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
相關文檔
文檔內容是否對您有幫助?