全部产品

剪辑合成

本文介绍如何通过ICE Java SDK创建合成任务。

创建合成任务

创建合成任务有三种方式:

  1. 通过时间线创建

  2. 通过模板创建

  3. 通过project创建

以上三种方式任选其一

获取单个合成任务

通过GetMediaProducingJob接口获取合成任务的输入、输出及状态。

代码示例

package com.aliyun.ice.sample;

import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.ice20201109.Client;

/**
 * @author :xxxxx
 * @date :Created in 2021/1/12
 */
public class MediaProducingJobSample {
    public static void main (String args[]) {
        try {
            // 初始化SDK
            Config config = new Config();
            config.accessKeyId = "<yourAccessKeyId>";
            config.accessKeySecret = "<yourAccessKeySecret>";
            config.endpoint = "ice.cn-shanghai.aliyuncs.com";
            config.regionId = "cn-shanghai";
            Client iceClient = new Client(config);

            // 通过timeline创建合成任务
            SubmitMediaProducingJobRequest submitMediaProducingJobRequest1 = new SubmitMediaProducingJobRequest();
            submitMediaProducingJobRequest1.setTimeline("{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"}]}]}");
            submitMediaProducingJobRequest1.setOutputMediaConfig("{\"MediaURL\":\"http://****.sample.com/ice/\"}");
            submitMediaProducingJobRequest1.setProjectMetadata("{\"coverURL\":\"http://test.sample.com/media/cover/mediaid.jpg\",\"description\":\"description\",\"title\":\"title\",\"tags\":\"Tag1,Tag2,Test\"}");
            SubmitMediaProducingJobResponse submitMediaProducingJobResponse1 = iceClient.submitMediaProducingJob(submitMediaProducingJobRequest1);
            System.out.println("requestId : " + submitMediaProducingJobResponse1.getBody().getRequestId());
            System.out.println("jobId : " + submitMediaProducingJobResponse1.getBody().getJobId());
            System.out.println("projectId : " + submitMediaProducingJobResponse1.getBody().getProjectId());

            // 通过模板创建合成任务
            SubmitMediaProducingJobRequest submitMediaProducingJobRequest2 = new SubmitMediaProducingJobRequest();
            submitMediaProducingJobRequest2.setTemplateId("IceSys_VideoMerge");
            submitMediaProducingJobRequest2.setClipsParam("{\"VideoArray\":[\"****05512043f49f697f7425****\",\"****2788e810116a45109f2e****\",\"****67f44f4964e6c998dee8****\",]}");
            submitMediaProducingJobRequest2.setOutputMediaConfig("{\"MediaURL\":\"http://****.sample.com/ice/\"}");
            SubmitMediaProducingJobResponse submitMediaProducingJobResponse2 = iceClient.submitMediaProducingJob(submitMediaProducingJobRequest2);
            System.out.println("requestId : " + submitMediaProducingJobResponse2.getBody().getRequestId());
            System.out.println("jobId : " + submitMediaProducingJobResponse2.getBody().getJobId());
            System.out.println("projectId : " + submitMediaProducingJobResponse2.getBody().getProjectId());

            // 通过project创建合成任务
            SubmitMediaProducingJobRequest submitMediaProducingJobRequest3 = new SubmitMediaProducingJobRequest();
            submitMediaProducingJobRequest3.setProjectId("****67f44f4964e6c998dee8****");
            submitMediaProducingJobRequest3.setOutputMediaConfig("{\"MediaURL\":\"http://****.sample.com/ice/\"}");
            SubmitMediaProducingJobResponse submitMediaProducingJobResponse3 = iceClient.submitMediaProducingJob(submitMediaProducingJobRequest3);
            System.out.println("requestId : " + submitMediaProducingJobResponse3.getBody().getRequestId());
            System.out.println("jobId : " + submitMediaProducingJobResponse3.getBody().getJobId());
            System.out.println("projectId : " + submitMediaProducingJobResponse3.getBody().getProjectId());

            // 获取单个合成任务
            GetMediaProducingJobRequest request = new GetMediaProducingJobRequest();
            request.setJobId("****67f44f4964e6c998dee8****");
            GetMediaProducingJobResponse reqponse = iceClient.getMediaProducingJob(request);
            System.out.println("jobId : " + reqponse.getBody().getMediaProducingJob().getJobId());
            System.out.println("status : " + reqponse.getBody().getMediaProducingJob().getStatus());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}