Opening and tail slates are clips with key information that are embedded as Picture-in-Picture (PiP) overlays at the beginning and end of a main video. This topic provides PHP SDK sample code for adding opening and tail slates by using ApsaraVideo Media Processing.
Prerequisites
MPS SDK for PHP is installed and configured. For more information, see MPS SDK for PHP. To obtain more information about the SDK and view examples on how to use the SDK to call API operations, visit OpenAPI Explorer.
Start and End Panels
Call the SubmitJobs operation to set opening and ending parts during video merging. For more information about the request and response parameters, see SubmitJobs. Sample request:
<?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"; # The ID of the transcoding template. Select a template as needed.
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
* We recommend that you set the protocol parameter to HTTPS in a production environment.
*/
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->headObject))
),
"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->ossOutputObject));
$output['Video'] = array('Width' => 1280,
'Height' => 720);
$output['TemplateId'] = $this->templateId;
# Configure parameters to set the opening part.
$openingVideo = array('OpenUrl' => 'http://'.$bucket.'.'.$ossLocation.'.aliyuncs.com/'.urlencode($headObject),
'Width' => 640,
'Start' => 2);
$output['OpeningList'] = array($openingVideo);
# Configure parameters to 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);
return json_encode($outputs);
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
该文章对您有帮助吗?