Transcoding is to convert an audio or video file into another one or more audio or video files to adapt to different network bandwidths, terminal devices, and user needs. If the transcoding jobs and workflows created in the ApsaraVideo Media Processing (MPS) console cannot meet your business requirements, you can call the SubmitJobs operation to submit a transcoding job. This topic provides an example on how to use MPS SDK for PHP V2.0 to transcode media files.
For more information about the API operations that are used to manage transcoding jobs and the parameters of the API operations, see SubmitJobs.
Sample code
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SubmitJobsRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* Use your AccessKey ID and AccessKey secret to initialize the client.
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured.
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured.
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$submitJobsRequest = new SubmitJobsRequest([
// The job input.
"input" => "{\"Bucket\":\"exampleBucket\",\"Location\":\"oss-cn-hangzhou\",\"Object\":\"example.flv\",\"Referer\": \"The parameter that you set in the Object Storage Service (OSS) console to enable the hotlink protection feature\"}",
// The job output configuration.
"outputs" => "[{\"OutputObject\":\"exampleOutput.mp4\",\"TemplateId\":\"6181666213ab41b9bc21da8ff5ff****\",\"WaterMarks\":[{\"InputFile\":{\"Bucket\":\"exampleBucket\",\"Location\":\"oss-cn-hangzhou\",\"Object\":\"image_01.png\"},\"WaterMarkTemplateId\":\"9b772ce2740d4d55876d8b542d47****\"}],\"UserData\":\"testid-001\"}]",
// The OSS bucket that stores the output file.
"outputBucket" => "exampleBucket",
// The region in which the OSS bucket resides.
"outputLocation" => "oss-cn-hangzhou",
// The ID of the MPS queue.
"pipelineId" => "dd3dae411e704030b921e52698e5****"
]);
$runtime = new RuntimeOptions([]);
try {
// Write your own code to display the response of the API operation if necessary.
$client->submitJobsWithOptions($submitJobsRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only.
// The error message.
var_dump($error->message);
// The URL of the corresponding error diagnostics page.
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));