Media production

Updated at:

By reading this article, you can learn the sample code for creating an intelligent media service clip composition task by calling the OpenAPI of the server SDK.

Usage notes

When you create a production job, use one of the following parameters: `Timeline`, `TemplateId`, or `ProjectId`.

Sample code

For online debugging, visit Alibaba Cloud OpenAPI Developer Portal.

<?php

require_once '../vendor/autoload.php';

use AlibabaCloud\SDK\ICE\V20201109\ICE;
use AlibabaCloud\SDK\ICE\V20201109\Models;
use AlibabaCloud\SDK\ICE\V20201109\Models\SubmitMediaProducingJobRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetMediaProducingJobRequest;
use Darabonba\OpenApi\Models\Config;

try {

    // An AccessKey of an Alibaba Cloud account has permissions to access all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M.
    // This example shows how to save the AccessKey ID and AccessKey secret in environment variables. For more information about how to configure credentials, see: https://help.aliyun.com/document_detail/311677.html
    $credential = new Credential([]);
    $config = new Config([
     'credential' => $credential,
     'endpoint' => 'ice.cn-shanghai.aliyuncs.com'
    ]);
    // To hard-code the AccessKey ID and AccessKey secret, use the following code. We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey leak and threaten the security of all resources in your account.
    // $config->accessKeyId = '<yourAccessKeyId>';
    // $config->accessKeySecret = '<yourAccessKeySecret>';
    $client = new ICE($config);

    // Create a production job using a timeline.
    $request = new SubmitMediaProducingJobRequest();
    $request->timeline = "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"****b4d7cf14dc7b83b0e801cbe****\"}]}]}";
    $request->projectMetadata = "{\"coverURL\":\"http://***sample.test.com/media/cover/mediaid.jpg\",\"description\":\"description\",\"title\":\"title\",\"tags\":\"Tag1,Tag2,Test\"}";
    $request->outputMediaConfig = "{\"mediaURL\":\"https://***sample.aliyuncs.com/ice/***\"}";
    $response = $client->submitMediaProducingJob($request);
    var_dump($response);
    $jobId = $response->body->jobId;

    // Create a production job using a template.
    $request = new SubmitMediaProducingJobRequest();
    $request->templateId = "IceSys_VideoMerge";
    $request->clipsParam = "{\"VideoArray\":[\"****as05512043f49f697f7425as****\",\"****as2788e810116a45109f2efd****\",\"****sd67f44f4964e6c998dee8df****\",]}";
    $request->outputMediaConfig = "{\"mediaURL\":\"https://***sample.aliyuncs.com/ice/***\"}";
    $response = $client->submitMediaProducingJob($request);
    var_dump($response);
    $jobId = $response->body->jobId;

    // Create a production job using a project.
    $request = new SubmitMediaProducingJobRequest();
    $request->projectId = "****9b4d7cf14dc7b83b0e801cbe****";
    $request->outputMediaConfig = "{\"mediaURL\":\"https://***sample.aliyuncs.com/ice/***\"}";
    $response = $client->submitMediaProducingJob($request);
    var_dump($response);

    // Obtain a single production job.
    $request = new GetMediaProducingJobRequest();
    $request->jobId = $jobId;
    $response = $client->getMediaProducingJob($request);
    var_dump($response);

} catch (TeaUnableRetryError $e) {
    var_dump($e->getMessage());
    var_dump($e->getErrorInfo());
    var_dump($e->getLastException());
    var_dump($e->getLastRequest());
}

Related API operations