转码是将音视频文件转换成另一个或多个音视频文件,以适应不同网络带宽、不同终端设备和不同的用户需求。当控制台创建的转码任务和工作流均无法满足您的使用场景时,可以按需调用SubmitJobs接口进行转码。本文提供了媒体处理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";
/**
* @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->oss_input_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['TemplateId'] = $this->templateId;
$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();
查询转码作业
调用QueryJobList查询转码作业,接口参数和返回字段详细信息请参见查询转码作业,调用示例如下:
<?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\QueryJobListRequest;
class Sample {
/**
* @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 QueryJobListRequest([
"jobIds" => "bb558c1cc5be44d19****,d1ce193f50f1fcd****"
]);
$response = $client->queryJobList($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
遍历转码作业
调用ListJob查询转码作业,接口参数和返回字段详细信息请参见遍历转码作业,调用示例如下:
<?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\ListJobRequest;
class Sample {
/**
* @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 ListJobRequest([
"state" => "All",
"pipelineId" => "88c6ca185b665e2a12*****"
]);
$response = $client->listJob($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
取消转码作业
调用CancelJob查询转码作业,接口参数和返回字段详细信息请参见取消转码作业,调用示例如下:
<?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\CancelJobRequest;
class Sample {
/**
* @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 CancelJobRequest([
"jobId" => "d1ce4d49419193f50f1fcd*****"
]);
$response = $client->cancelJob($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
相关文档
文档内容是否对您有帮助?