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 the sample code for using MPS SDK for PHP to add a media file to the media library and trigger a specific workflow to process the media file.
Note
If the directory of the media file that you want to add 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
require_once './aliyun-php-sdk-core/Config.php';
use Mts\Request\V20140618 as Mts;
function initMtsClient($accessKeyId, $accessKeySecret) {
$regionId = 'cn-shanghai'; // The ID of the region in which your MPS service is deployed.
$profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
return new DefaultAcsClient($profile);
}
try {
$client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
$response = addMedia($client);
print_r($response);
} catch (Exception $e) {
print $e->getMessage()."\n";
}
function addMedia($client) {
$request = new Mts\AddMediaRequest();
$request->setFileURL("http://<bucket name>.oss-cn-shanghai.aliyuncs.com/media/video.mp4");
$request->setMediaWorkflowId("829bed036de957e3421****");
return $client->getAcsResponse($request);
}