You need to enable JavaScript to run this app.
导航
视频剪辑
最近更新时间:2024.09.29 17:41:41首次发布时间:2022.07.22 20:20:54

本文为您提供了服务端 Java SDK 的视频剪辑模块的接口调用示例。

前提条件

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

调用示例

提交异步剪辑任务

接口请求参数和返回参数说明详见提交异步剪辑任务

package com.volcengine.example.vod.edit;

import com.google.protobuf.ByteString;
import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
import com.volcengine.service.vod.model.request.VodSubmitDirectEditTaskAsyncRequest;
import com.volcengine.service.vod.model.response.VodSubmitDirectEditTaskAsyncResponse;

import java.nio.charset.StandardCharsets;

public class VodSubmitDirectEditTaskAsyncDemo {

    public static void main(String[] args) {
        // 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");

        VodSubmitDirectEditTaskAsyncRequest vodSubmitDirectEditTaskAsyncRequest = VodSubmitDirectEditTaskAsyncRequest.newBuilder()
                .setUploader("your space")
                .setApplication("VideoTrackToB")
                .setEditParam(ByteString.copyFromUtf8("your params"))
                .build();

        try {
            VodSubmitDirectEditTaskAsyncResponse vodSubmitDirectEditTaskAsyncResponse = vodService.submitDirectEditTaskAsync(vodSubmitDirectEditTaskAsyncRequest);
            if (vodSubmitDirectEditTaskAsyncResponse.getResponseMetadata().hasError()) {
                System.out.println(vodSubmitDirectEditTaskAsyncResponse.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(vodSubmitDirectEditTaskAsyncResponse.toString()); // 编码采用UTF8
            System.out.println(vodSubmitDirectEditTaskAsyncResponse.getResponseMetadata().getRequestId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

提交同步剪辑任务

接口请求参数和返回参数说明详见提交同步剪辑任务

package com.volcengine.example.vod.edit;

import com.google.protobuf.ByteString;
import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
import com.volcengine.service.vod.model.request.VodSubmitDirectEditTaskSyncRequest;
import com.volcengine.service.vod.model.response.VodSubmitDirectEditTaskSyncResponse;

public class VodSubmitDirectEditTaskSyncDemo {

    public static void main(String[] args) {
        // 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");

        VodSubmitDirectEditTaskSyncRequest vodSubmitDirectEditTaskSyncRequest = VodSubmitDirectEditTaskSyncRequest.newBuilder()
                .setUploader("your space")
                .setApplication("SimpleCut")
                .setEditParam(ByteString.copyFromUtf8("your params"))
                .build();

        try {
            VodSubmitDirectEditTaskSyncResponse vodSubmitDirectEditTaskSyncResponse = vodService.submitDirectEditTaskSync(vodSubmitDirectEditTaskSyncRequest);
            if (vodSubmitDirectEditTaskSyncResponse.getResponseMetadata().hasError()) {
                System.out.println(vodSubmitDirectEditTaskSyncResponse.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(vodSubmitDirectEditTaskSyncResponse.toString()); // 编码采用UTF8
            System.out.println(vodSubmitDirectEditTaskSyncResponse.getResponseMetadata().getRequestId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

取消剪辑任务

接口请求参数和返回参数说明详见取消剪辑任务

package com.volcengine.example.vod.edit;

import com.google.protobuf.util.JsonFormat;
import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
import com.volcengine.service.vod.model.request.VodCancelDirectEditTaskRequest;

import com.volcengine.service.vod.model.response.VodCancelDirectEditTaskResponse;
import com.volcengine.service.vod.model.response.VodGetDirectEditProgressResponse;

public class VodCancelDirectEditTaskDemo {

    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");

        VodCancelDirectEditTaskRequest vodCancelDirectEditTaskRequest = VodCancelDirectEditTaskRequest.newBuilder()
                .setReqId("your reqId")
                .build();

        try {
            VodCancelDirectEditTaskResponse vodCancelDirectEditTaskResponse = vodService.cancelDirectEditTask(vodCancelDirectEditTaskRequest);
            if (vodCancelDirectEditTaskResponse.getResponseMetadata().hasError()) {
                System.out.println(vodCancelDirectEditTaskResponse.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(JsonFormat.printer().includingDefaultValueFields().print(vodCancelDirectEditTaskResponse));// 如有汉字,请采用UTF8编码方式
            System.out.println(vodCancelDirectEditTaskResponse.getResponseMetadata().getRequestId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

查询任务进度

接口请求参数和返回参数说明详见查询任务进度

package com.volcengine.example.vod.edit;

import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
import com.volcengine.service.vod.model.request.VodGetDirectEditProgressRequest;
import com.volcengine.service.vod.model.response.VodGetDirectEditProgressResponse;

public class VodGetDirectEditProgressDemo {

    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");

        VodGetDirectEditProgressRequest vodGetDirectEditProgressRequest = VodGetDirectEditProgressRequest.newBuilder()
                .setReqId("your reqId")
                .build();

        try {
            VodGetDirectEditProgressResponse vodGetDirectEditProgressResponse = vodService.getDirectEditProgress(vodGetDirectEditProgressRequest);
            if (vodGetDirectEditProgressResponse.getResponseMetadata().hasError()) {
                System.out.println(vodGetDirectEditProgressResponse.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(vodGetDirectEditProgressResponse.toString()); // 如有汉字,请采用UTF8编码方式
            System.out.println(vodGetDirectEditProgressResponse.getResponseMetadata().getRequestId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

注意事项

返回结果 Result 参数说明如下所示。

  • 返回的结果 Result 参数为空时,即 Result:{ } ,进度为 0。代码示例如下所示。
ResponseMetadata:{
   RequestId:"2022102***2121601360E968B6F" 
   Action:"GetDirectEditProgress" 
   Version:"2018-01-01" 
   Service:"vod" 
   Region:"cn-north-1"
   } 
Result:{
   }
  • 返回的结果 Result 参数有具体数值时,进度为对应的具体数值。代码示例如下所示。
ResponseMetadata:{
   RequestId:"2022102815***21601360E968B6F" 
   Action:"GetDirectEditProgress" 
   Version:"2018-01-01" 
   Service:"vod" 
   Region:"cn-north-1"
} 
Result:{
   Result:100
}

查询任务详情

接口请求参数和返回参数说明详见查询任务详情

package com.volcengine.example.vod.edit;

import com.google.protobuf.Descriptors;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
import com.volcengine.service.vod.model.business.GetDirectEditResult;
import com.volcengine.service.vod.model.request.VodGetDirectEditResultRequest;
import com.volcengine.service.vod.model.response.VodGetDirectEditResultResponse;

import java.util.Map;

public class VodGetDirectEditResultDemo {

    public static void main(String[] args) {
        // 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");

        VodGetDirectEditResultRequest vodGetDirectEditResultRequest = VodGetDirectEditResultRequest.newBuilder()
                .addReqIds("your reqId")
                .build();

        try {
            VodGetDirectEditResultResponse vodGetDirectEditResultResponse = vodService.getDirectEditResult(vodGetDirectEditResultRequest);
            if (vodGetDirectEditResultResponse.getResponseMetadata().hasError()) {
                System.out.println(vodGetDirectEditResultResponse.getResponseMetadata().getError());
                System.exit(-1);
            }
            System.out.println(vodGetDirectEditResultResponse.toString()); // 如有汉字,请采用UTF8编码方式
            System.out.println(vodGetDirectEditResultResponse.getResponseMetadata().getRequestId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}