通过阅读本文,您可以了解通过服务端SDK调用OpenAPI创建智能媒体服务剪辑合成任务的示例代码。
使用说明
创建合成任务时,您可以根据实际需求通过Timeline、TemplateId或ProjectId其中之一创建。
示例代码
您可以通过阿里云OpenAPI开发者门户在线调试。
package com.aliyun.ice.sample;
import com.aliyun.ice20201109.Client;
import com.aliyun.ice20201109.models.*;
import com.aliyun.teaopenapi.models.Config;
public class MediaProducingJobSample {
public static void main (String[] args) throws Exception{
// 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
// 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config();
config.setCredential(credentialClient);
// 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// config.accessKeyId = <yourAccessKeyId>;
// config.accessKeySecret = <yourAccessKeySecret>;
config.endpoint = "ice.cn-shanghai.aliyuncs.com";
Client client = new Client(config);
// 通过Timeline创建合成任务
SubmitMediaProducingJobRequest submitMediaProducingJobRequest1 = new SubmitMediaProducingJobRequest();
submitMediaProducingJobRequest1.setTimeline("{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"}]}]}");
submitMediaProducingJobRequest1.setOutputMediaConfig("{\"MediaURL\":\"http://example-bucket.oss-object.com/example.mp4\"}");
submitMediaProducingJobRequest1.setProjectMetadata("{\"coverURL\":\"http://test.sample.com/mediaid.jpg\",\"description\":\"description\",\"title\":\"title\",\"tags\":\"Tag1,Tag2,Test\"}");
SubmitMediaProducingJobResponse submitMediaProducingJobResponse1 = client.submitMediaProducingJob(submitMediaProducingJobRequest1);
System.out.println("requestId : " + submitMediaProducingJobResponse1.getBody().getRequestId());
System.out.println("jobId : " + submitMediaProducingJobResponse1.getBody().getJobId());
System.out.println("projectId : " + submitMediaProducingJobResponse1.getBody().getProjectId());
// 通过TemplateId创建合成任务
SubmitMediaProducingJobRequest submitMediaProducingJobRequest2 = new SubmitMediaProducingJobRequest();
submitMediaProducingJobRequest2.setTemplateId("IceSys_VideoMerge");
submitMediaProducingJobRequest2.setClipsParam("{\"VideoArray\":[\"****05512043f49f697f7425****\",\"****2788e810116a45109f2e****\",\"****67f44f4964e6c998dee8****\",]}");
submitMediaProducingJobRequest2.setOutputMediaConfig("{\"MediaURL\":\"http://example-bucket.oss-object.com/example.mp4\"}");
SubmitMediaProducingJobResponse submitMediaProducingJobResponse2 = client.submitMediaProducingJob(submitMediaProducingJobRequest2);
System.out.println("requestId : " + submitMediaProducingJobResponse2.getBody().getRequestId());
System.out.println("jobId : " + submitMediaProducingJobResponse2.getBody().getJobId());
System.out.println("projectId : " + submitMediaProducingJobResponse2.getBody().getProjectId());
// 通过ProjectId创建合成任务
SubmitMediaProducingJobRequest submitMediaProducingJobRequest3 = new SubmitMediaProducingJobRequest();
submitMediaProducingJobRequest3.setProjectId("****67f44f4964e6c998dee8****");
submitMediaProducingJobRequest3.setOutputMediaConfig("{\"MediaURL\":\"http://example-bucket.oss-object.com/example.mp4\"}");
SubmitMediaProducingJobResponse submitMediaProducingJobResponse3 = client.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 = client.getMediaProducingJob(request);
System.out.println("jobId : " + reqponse.getBody().getMediaProducingJob().getJobId());
System.out.println("status : " + reqponse.getBody().getMediaProducingJob().getStatus());
// 通过直播流区间提交合成
SubmitLiveEditingJobRequest submitLiveEditingJobRequest = new SubmitLiveEditingJobRequest();
submitLiveEditingJobRequest.setClips("[{\"StartTime\":\"2021-06-21T08:01:00Z\",\"EndTime\":\"2021-06-21T08:03:00Z\",\"AppName\":\"app\",\"DomainName\":\"domain.com\",\"StreamName\":\"stream\"},{\"StartTime\":\"2021-06-21T08:05:00Z\",\"EndTime\":\"2021-06-21T08:09:00Z\"}]");
submitLiveEditingJobRequest.setProjectId("****fddd7748b58bf1d47e95****");
submitLiveEditingJobRequest.setLiveStreamConfig("{ \"AppName\": \"app\", \"DomainName\": \"domain.com\", \"StreamName\": \"stream\" }");
submitLiveEditingJobRequest.setOutputMediaConfig("{ \"MediaURL\": \"https://example-bucket.oss-cn-shanghai.aliyuncs.com/testfile.mp4\" }");
submitLiveEditingJobRequest.setMediaProduceConfig("{ \"Mode\": \"AccurateFast\"}");
submitLiveEditingJobRequest.setUserData("{\"key\": \"value\"}");
submitLiveEditingJobRequest.setOutputMediaTarget("oss-object");
SubmitLiveEditingJobResponse submitLiveEditingJobResponse = client.submitLiveEditingJob(submitLiveEditingJobRequest);
System.out.println("jobId:"+submitLiveEditingJobResponse.getBody().getJobId());
System.out.println("requestid:"+submitLiveEditingJobResponse.getBody().getRequestId());
// 通过直播JobId获取单个信息
GetLiveEditingJobRequest getLiveEditingJobRequest = new GetLiveEditingJobRequest();
getLiveEditingJobRequest.setJobId("****d80e4e4044975745c14b****");
GetLiveEditingJobResponse getLiveEditingJobResponse = client.getLiveEditingJob(getLiveEditingJobRequest);
System.out.println("state:"+getLiveEditingJobResponse.getBody().getLiveEditingJob().getStatus());
}
}
相关接口
文档内容是否对您有帮助?