After you add a media file to the media library of ApsaraVideo Media Processing (MPS), you can specify the ID of a workflow to process the media file. This topic provides an example on how to use MPS SDK for PHP V2.0 to add a media file to the media library and trigger a specific workflow to process the media file.
Note
If the media library meets the triggering rules of a workflow, the workflow is triggered. Otherwise, the workflow is not triggered. For more information, see Workflow triggering rules for files.
<?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\AddMediaRequest;
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();
$addMediaRequest = new AddMediaRequest([
// The path of the input file.
"fileURL" => "http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test.mp4",
// The media title.
"title" => "mytest",
// The description.
"description" => "A test video",
// The URL of the media thumbnail.
"coverURL" => "http://bucket.oss-cn-hangzhou.aliyuncs.com/example/1.png",
// The tags.
"tags" => "tag1,tag2",
// The ID of the media workflow.
"mediaWorkflowId" => "07da6c65da7f458997336e0de192****",
// The custom data of the media workflow.
"mediaWorkflowUserData" => "test",
// Specify whether to check if the media workflow supports the specified input path.
"inputUnbind" => false,
// The ID of the category to which the media file belongs.
"cateId" => 123,
// Set the overrideParams parameter.
"overrideParams" => "{“subtitleTransNodeName”:{“InputConfig”:{“Format”:”stl”,”InputFile”:{“URL”:”http://exampleBucket.oss-cn-hangzhou.aliyuncs.com/package/example/CENG.stl\"}}}}"
]);
$runtime = new RuntimeOptions([]);
try {
// Write your own code to display the response of the API operation if necessary.
$client->addMediaWithOptions($addMediaRequest, $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));