Add a media workflow

更新时间:
复制 MD 格式

You can create a media workflow to produce videos with multiple bitrates, audio tracks, captions, or formats. A workflow lets you orchestrate a series of tasks and execute them in a predefined sequence. In a workflow, you can add task nodes for transcoding, analysis, thumbnail generation, packaging (encapsulation), review, media fingerprint extraction, and smart thumbnail settings. This topic provides sample code that shows how to add a media workflow using the ApsaraVideo Media Processing Java software development kit (SDK) V2.0.

Sample code

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Use an AccessKey pair (AccessKey ID and AccessKey secret) to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.AddMediaWorkflowRequest addMediaWorkflowRequest = new com.aliyun.mts20140618.models.AddMediaWorkflowRequest()
                // The name of the media workflow.
                .setName("mediaworkflow-example")
                // The trigger mode.
                .setTriggerMode("OssAutoTrigger")
                // The topology of the media workflow.
                .setTopology("{\"Activities\": {\"mediaworkflow-example\": {\"Parameters\": {\"Outputs\": \"[{\\\"OutputObject\\\":\\\"examplebucket/output/{RunId}/TRANSCODE_165941222****/{FileName}\\\",\\\"TemplateId\\\":\\\"S00000001-200010\\\",\\\"TemplateName\\\":\\\"MP4-Low Definition\\\"}]\",\"OutputBucket\": \"examplebucket\",\"OutputLocation\": \"oss-cn-shanghai\"},\"Type\": \"Transcode\"},\"Act-Start\": {\"Parameters\": {\"PipelineId\": \"a7d481f07d8c45da88c71853ce7d****\",\"InputFile\": \"{\\\"Bucket\\\":\\\"example-input\\\",\\\"Location\\\":\\\"oss-cn-shanghai\\\",\\\"ObjectPrefix\\\":\\\"mps-test/input/\\\"}\"},\"Type\": \"Start\"},\"Act-Report\": {\"Parameters\": {\"PublishType\": \"Manual\"},\"Type\": \"Report\"}},\"Dependencies\": {\"mediaworkflow-example\": [\"Act-Report\"],\"Act-Start\": [\"mediaworkflow-example\"],\"Act-Report\": []}}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Copy the code to run it. Print the return value of the API.
            client.addMediaWorkflowWithOptions(addMediaWorkflowRequest, runtime);
        } catch (TeaException error) {
            // This is for printing only. Handle exceptions with caution. Do not ignore exceptions in your project.
            // The error message.
            System.out.println(error.getMessage());
            // The diagnosis address.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This is for printing only. Handle exceptions with caution. Do not ignore exceptions in your project.
            // The error message.
            System.out.println(error.getMessage());
            // The diagnosis address.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

References