本示例介绍如何使用Alibaba Cloud SDK for Java调用SubmitMediaInfoJob接口创建一个提交媒体信息作业。

提交媒体信息作业接口,媒体处理(ApsaraVideo for Media Processing,原MTS)服务会对输入文件进行媒体信息分析,同步返回输入文件的媒体信息。可通过SubmitMediaInfoJob接口得到媒体信息分析结果。

前提条件

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-mts</artifactId>
    <version>2.7.2</version>
</dependency>

示例代码

package com.ygx.program;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobRequest;
import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

public class TestSubmitMediaInfoJob {

    public static void main(String[] args) {
        // 创建SubmitMediaInfoJob实例并初始化
        DefaultProfile profile = DefaultProfile.getProfile(
                "<your-region-id>",            // 地域ID
                "<your-access-key-id>",        // 您的AccessKey ID
                "<your-access-key-secret>" );  // 您的AccessKey Secret
        IAcsClient client = new DefaultAcsClient(profile);
        SubmitMediaInfoJobRequest request = new SubmitMediaInfoJobRequest();
        /*
         * 作业输入,Json对象,例如:
         * {
         *   "Bucket": "example-bucket",
         *   "Location": "oss-cn-hangzhou",
         *   "Object": "example.flv"
         *    }需在控制台授予此Bucket权限给媒体转码服务。
         */
        try {
            // 输入文件名,路径   注意: 路径需要转码
            String OssInputObject = URLEncoder.encode("example.flv", "utf-8");
            String inputStr = "{\"Bucket\":\"example-bucket\","      // 输出Bucket
                    + "\"Location\":\"oss-cn-hangzhou\","            // 输出Bucket所在地域
                    + "\"Object\":\" " + OssInputObject + "\"}";     // 输入文件名,路径   注意 路径需要
            request.setInput(inputStr);
            //System.out.println(new Gson().toJson(request));
            SubmitMediaInfoJobResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        } 
    }
}
说明 更多SubmitMediaInfoJob接口内容,请参见API参考