This topic describes the sample code that is used to call API operations by using the server SDK to create an editing and production job in Intelligent Media Services (IMS).
Usage notes
You can create a production job by using Timeline, TemplateId, or ProjectId based on your business requirements.
Sample code
You can use Alibaba Cloud OpenAPI Explorer to perform online debugging.
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{
// An AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use an AccessKey pair of a RAM user to call API operations or perform routine O&M.
// In this example, the AccessKey ID and AccessKey secret are obtained from the environment variables. For more information, visit https://www.alibabacloud.com/help/en/sdk/developer-reference/v2-manage-access-credentials?spm=a3c0i.23458820.2359477120.17.332f6e9bDw0ggo.
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config();
config.setCredential(credentialClient);
// To hard-code your AccessKey ID and AccessKey secret, use the following code. However, we recommend that you do not save the AccessKey ID and the AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of resources within your account may be compromised.
// config.accessKeyId = <yourAccessKeyId>;
// config.accessKeySecret = <yourAccessKeySecret>;
config.endpoint = "ice.cn-shanghai.aliyuncs.com";
Client client = new Client(config);
// Create a production job by using 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());
// Create a production job by using 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());
// Create a production job by using 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());
// Obtain a single production job.
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());
// Submit a production job by specifying live stream clips.
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());
// Obtain information about a single live stream job by using JobId.
GetLiveEditingJobRequest getLiveEditingJobRequest = new GetLiveEditingJobRequest();
getLiveEditingJobRequest.setJobId("****d80e4e4044975745c14b****");
GetLiveEditingJobResponse getLiveEditingJobResponse = client.getLiveEditingJob(getLiveEditingJobRequest);
System.out.println("state:"+getLiveEditingJobResponse.getBody().getLiveEditingJob().getStatus());
}
}