ユーザーは MPS の提供するトランスコードやスクリーンショットなどのアクティビティを、トポロジーに組み込むことができます。 トポロジーは次のとおりです。

トポロジー型
  1. package com.aliyun.mts;import com.alibaba.fastjson.annotation.JSONField;import java.util.List;import java.util.Map;public class Topology { @JSONField(name = Activities”) private Map<String, Activity> activities; @JSONField(name = Dependencies”) private Map<String, List<String>> dependencies; public Map<String, List<String>> dependencies() { return this.getDependencies(); } public Topology() { } public Topology(Map<String, Activity> activities, Map<String, List<String>> dependencies) { this.setActivities(activities); this.setDependencies(dependencies); } public Map<String, Activity> getActivities() { return activities; } public Map<String, List<String>> getDependencies() { return dependencies; } public void setActivities(Map<String, Activity> activities) { this.activities = activities; } public void setDependencies(Map<String, List<String>> dependencies) { this.dependencies = dependencies; }}
  1. <div class="p">ActivityType 列挙型
  2. <pre class="pre codeblock"><code>package com.aliyun.mts;

/**

  • Created by zhongyizengzy on 18/3/22.*/public enum ActivityType { Start, Transcode, Snapshot, MediaInfo, Analysis, Cover, Summary, Censor, Report, UploadVerify, GenerateMasterPlayList, AudioGroup, SubtitleGroup, PackageConfig}

    1. </div>
    2. <div class="p">Activity 型
    3. <pre class="pre codeblock"><code>package com.aliyun.mts;

    import com.alibaba.fastjson.annotation.JSONField;import java.util.Map;public class Activity { @JSONField(name = “Type”) private String type; @JSONField(name = “Parameters”) private Map<String, String> parameters; public Activity() { } public Map<String, String> parameters() {

    1. return this.getParameters();

    } public Activity(String type, Map<String, String> parameters) {

    1. this.setType(type);
    2. this.setParameters(parameters);

    } public String getType() {

    1. return type;

    } public Map<String, String> getParameters() {

    1. return parameters;

    } public void setType(String type) {

    1. this.type = type;

    } public void setParameters(Map<String, String> parameters) {

    1. this.parameters = parameters;

    }}

    1. </div>
    2. <div class="p">AddMediaWorkflow 型
    3. <pre class="pre codeblock"><code>package com.aliyun.mts;

    import com.alibaba.fastjson.JSONArray;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. AddMediaWorkflowRequest;import com.aliyuncs.mts.model.v20140618. AddMediaWorkflowResponse;import com.aliyuncs.profile.DefaultProfile;import org.apache.commons.lang.exception.ExceptionUtils;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;public class AddMediaWorkflow { //Step 1 .set region:cn-hangzhou、cn-shenzhen、cn-shanghai、cn-beijing 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”; //Step 2.set accesskey & keySecret private static String accessKeyId = “”; private static String accessKeySecret = “”; //Step 3.set mps transcoding queue id private static String PIPELINE_ID = “38bba54d524448be92d277caaa8da118”; private static DefaultAcsClient aliyunClient; static {

    1. try {
    2. DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
    3. } catch (ClientException e) {
    4. System.out.print(ExceptionUtils.getStackTrace(e));
    5. System.exit(1);
    6. }
    7. aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));

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

    1. AddMediaWorkflowRequest request = new AddMediaWorkflowRequest();
    2. request.setName("Sequential-workflow");
    3. Topology topology = new Topology();
    4. HashMap&lt;String, Activity&gt; activities = new HashMap&lt;String, Activity&gt;();
    5. Activity startNode = new Activity();
    6. startNode.setType(ActivityType.Start.name());
    7. HashMap&lt;String, String&gt; startNodeParameters = new HashMap&lt;String, String&gt;();
    8. JSONObject inputFile = new JSONObject();
    9. inputFile.put("Bucket", "mtb-sz-in");
    10. inputFile.put("Location", OSS_REGION);
    11. inputFile.put("ObjectPrefix", "media/");
    12. startNodeParameters.put("InputFile", inputFile.toString());
    13. startNodeParameters.put("PipelineId", PIPELINE_ID);
    14. startNode.setParameters(startNodeParameters);
    15. activities.put("startNode", startNode);
    16. Activity transcode = new Activity();
    17. transcode.setType(ActivityType.Transcode.name());
    18. HashMap&lt;String, String&gt; transcodingParameters = new HashMap&lt;String, String&gt;();
    19. JSONArray outputs = new JSONArray();
    20. JSONObject output = new JSONObject();
    21. try {
    22. output.put("OutputObject", URLEncoder.encode("transcode/{ObjectPrefix}/{FileName}.{ ExtName}", "UTF-8"));
    23. } catch (UnsupportedEncodingException e) {
    24. System.exit(1);
    25. }
    26. output.put("TemplateId", "S00000001-000070");
    27. outputs.add(output);
    28. transcodingParameters.put("Outputs", outputs.toJSONString());
    29. transcodingParameters.put("OutputBucket", "mtb-sz-out");
    30. transcodingParameters.put("OutputLocation", OSS_REGION);
    31. transcode.setParameters(transcodingParameters);
    32. activities.put("transcodingNode", transcode);
    33. Activity report = new Activity();
    34. report.setType(ActivityType.Report.name());
    35. HashMap&lt;String, String&gt; reportParameters = new HashMap&lt;String, String&gt;();
    36. report.setParameters(reportParameters);
    37. activities.put("reportNode", report);
    38. topology.setActivities(activities);
    39. HashMap&lt;String, List&lt;String&gt;&gt; dependencies = new HashMap&lt;String, List&lt;String&gt;&gt;();
    40. dependencies.put("startNode", Arrays.asList("transcodingNode"));
    41. dependencies.put("transcodingNode", Arrays.asList("reportNode"));
    42. dependencies.put("reportNode", new ArrayList&lt;String&gt;());
    43. topology.setDependencies(dependencies);
    44. request.setTopology(JSONObject.toJSONString(topology));
    45. try {
    46. AddMediaWorkflowResponse response = aliyunClient.getAcsResponse(request);
    47. System.out.println(JSONObject.toJSONString(response));
    48. } catch (ServerException e) {
    49. System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
    50. } catch (ClientException e) {
    51. System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
    52. }

    }}

    1. </div>
    2. </div>
    3. </article>