This topic provides the sample code for adding a video file to the media library. You can specify the ID of a workflow to process the video file.

package com.aliyun.mts;
    import com.alibaba.fastjson.JSONObject;
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.mts.model.v20140618.AddMediaRequest;
    import com.aliyuncs.mts.model.v20140618.AddMediaResponse;
    import com.aliyuncs.profile.DefaultProfile;
    import org.apache.commons.lang.exception.ExceptionUtils;
    public class AddMedia {
        // Specify the region in which you use the ApsaraVideo Media Processing (MPS) service, the region in which you use the Object Storage Service (OSS) service, and the endpoint used to access the MPS service.
        private static final String REGION = "cn-shenzhen";
        private static final String OSS_REGION = "oss-cn-shenzhen";
        private static final String mtsEndpoint = "mts." + REGION + ".aliyuncs.com";
        //Specify the AccessKey ID and the AccessKey secret.
        private static String accessKeyId = "";
        private static String accessKeySecret = "";
        private static DefaultAcsClient aliyunClient;
        static {
            try {
                DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
            } catch (ClientException e) {
                System.out.print(ExceptionUtils.getStackTrace(e));
                System.exit(1);
            }
            aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));
        }
        public static void main(String[] args) throws ClientException {
            AddMediaRequest request = new AddMediaRequest();
            request.setFileURL("http://example-bucket-****.oss-cn-shenzhen.aliyuncs.com/media/mpsFile****.mp4");
            request.setMediaWorkflowId("829bed0300994057a49e4f16de95****");
            try {
                AddMediaResponse response = aliyunClient.getAcsResponse(request);
                System.out.println(JSONObject.toJSONString(response));
            } catch (ServerException e) {
                System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
            } catch (ClientException e) {
                System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
            }
        }
    }