All Products
Search
Document Center

Intelligent Media Services:Transcoding jobs

Last Updated:Dec 30, 2024

This topic describes the sample code that is used to call API operations by using the server SDK to initiate and query a transcoding job in Intelligent Media Services (IMS).

Usage notes

When you initiate a transcoding job, you must specify the region (the region of the transcoding service), name (the name of the job), inputPath (the input OSS path of the job), outputpath (the output OSS path of the job), and templateId (the ID of the transcoding template) parameters. After the transcoding job is successfully processed, you can query information about the transcoding job based on the job ID returned in the JobId parameter.

Take note of the following items when you configure the parameters of transcoding jobs:

  • region specifies the region where the service is provided.

  • The name parameter can be left empty.

  • The region of the paths specified in the inputPath and outputpath parameters must be the same as region.

  • You can obtain transcoding template IDs required by the templateId parameter from the transcoding template management page of the console.

Note

The following regions are supported:

  • VOD media processing: China (Shanghai), China (Beijing), and China (Shenzhen)

  • Real-time media processing: China (Shanghai)

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 Sample {

    public static void main(String[] args) throws Exception {

        // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the 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. 
        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 transcoding job submission request.
        SubmitTranscodeJobRequest request = new SubmitTranscodeJobRequest()
            .setName("TranscodeTest")
            // Input information.
            .setInputGroup(java.util.Arrays.asList(
                new SubmitTranscodeJobRequest.SubmitTranscodeJobRequestInputGroup()
                    .setType("OSS")
                    .setMedia("oss://bucket/path/to/input_video.mp4")
            ))
            // Output information.
            .setOutputGroup(java.util.Arrays.asList(
                new SubmitTranscodeJobRequest.SubmitTranscodeJobRequestOutputGroup()
                    .setOutput(new SubmitTranscodeJobRequest.SubmitTranscodeJobRequestOutputGroupOutput()
                        .setType("OSS")
                        .setMedia("oss://bucket/path/to/output_video.mp4"))
                    .setProcessConfig(new SubmitTranscodeJobRequest.SubmitTranscodeJobRequestOutputGroupProcessConfig()
                        .setTranscode(new SubmitTranscodeJobRequest.SubmitTranscodeJobRequestOutputGroupProcessConfigTranscode()
                            .setTemplateId("9547c6ad97cb4f2aaa29683ebd18****")))
            ));
        // Send the transcoding job submission request.
        SubmitTranscodeJobResponse response = client.submitTranscodeJob(request);
        System.out.println("request id: " + response.getBody().getRequestId());

        // Retrieve the job ID and create a job query request.
        String jobId = response.body.transcodeParentJob.parentJobId;
        GetTranscodeJobRequest queryRequest = new GetTranscodeJobRequest()
           .setParentJobId(jobId);
        // Send the job query request.
        GetTranscodeJobResponse queryResponse = client.getTranscodeJob(queryRequest);
        System.out.println("request id: " + queryResponse.getBody().getRequestId());

    }
}

Related API operations