You need to enable JavaScript to run this app.
导航
媒体处理
最近更新时间:2024.09.29 17:41:40首次发布时间:2021.02.23 10:42:40

本文为您提供了服务端 Java SDK 的媒体处理模块的接口调用示例。

前提条件

调用接口前,请先完成 SDK 的安装初始化

调用示例

触发工作流

接口请求参数和返回参数说明详见触发工作流

package com.volcengine.example.vod.workflow;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodStartWorkflowDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodStartWorkflowRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodStartWorkflowRequest.newBuilder();
         reqBuilder.setVid("your Vid");
         reqBuilder.setTemplateId("your TemplateId");
         com.volcengine.service.vod.model.business.WorkflowParams.Builder inputBuilder = com.volcengine.service.vod.model.business.WorkflowParams.newBuilder();
         reqBuilder.setInput(inputBuilder);
         reqBuilder.setPriority(0);
         reqBuilder.setCallbackArgs("your CallbackArgs");
         reqBuilder.setEnableLowPriority(false);
         com.volcengine.service.vod.model.business.DirectUrl.Builder directUrlBuilder = com.volcengine.service.vod.model.business.DirectUrl.newBuilder();
         reqBuilder.setDirectUrl(directUrlBuilder);
         
            com.volcengine.service.vod.model.response.VodStartWorkflowResponse resp = vodService.startWorkflow(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

获取转码结果

接口请求参数和返回参数说明详见获取转码结果

package com.volcengine.example.vod.workflow;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodRetrieveTranscodeResultDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodRetrieveTranscodeResultRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodRetrieveTranscodeResultRequest.newBuilder();
         reqBuilder.setVid("your Vid");
         reqBuilder.setResultType("your ResultType");
         
            com.volcengine.service.vod.model.response.VodRetrieveTranscodeResultResponse resp = vodService.retrieveTranscodeResult(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

获取工作流运行状态

接口请求参数和返回参数说明详见获取工作流运行状态

package com.volcengine.example.vod.workflow;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodGetWorkflowExecutionDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodGetWorkflowExecutionStatusRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodGetWorkflowExecutionStatusRequest.newBuilder();
         reqBuilder.setRunId("your RunId");
            com.volcengine.service.vod.model.response.VodGetWorkflowExecutionStatusResponse resp = vodService.getWorkflowExecution(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

获取工作流执行结果

接口请求参数和返回参数说明详见获取工作流执行结果

package com.volcengine.example.vod.workflow;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
public class VodGetWorkflowExecutionResultDemo {

    public static void main(String[] args) throws Exception {
        // Create a VOD instance in the specified region.
        // IVodService vodService = VodServiceImpl.getInstance("cn-north-1");
        IVodService vodService = VodServiceImpl.getInstance();

        // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/65641.
        // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed.
        // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account.
        // vodService.setAccessKey("your ak");
        // vodService.setSecretKey("your sk");

        try {
            com.volcengine.service.vod.model.request.VodGetWorkflowResultRequest.Builder reqBuilder = com.volcengine.service.vod.model.request.VodGetWorkflowResultRequest.newBuilder();
         reqBuilder.setRunId("your RunId");
         
            com.volcengine.service.vod.model.response.VodGetWorkflowResultResponse resp = vodService.getWorkflowExecutionResult(reqBuilder.build());
            if (resp.getResponseMetadata().hasError()) {
                System.out.println(resp.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}