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

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

前提条件

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

调用示例

提交异步剪辑任务

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

package vod

import (
        "encoding/json"
        "fmt"
        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
        "google.golang.org/protobuf/encoding/protojson"
        "testing"
)

func Test_SubmitDirectEditTaskAsync(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // 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/65655.
        // 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.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        params, _ := json.Marshal(map[string]interface{}{})
        query := &request.VodSubmitDirectEditTaskAsyncRequest{
                Uploader:     "your target store vod space",
                Application:  "your application",
                EditParam:    params,
                Priority:     0,
                CallbackUri:  "your CallbackUri if you need",
                CallbackArgs: "your CallbackArgs if you need",
        }
        resp, status, err := instance.SubmitDirectEditTaskAsync(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

提交同步剪辑任务

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

// Code generated by protoc-gen-volcengine-sdk
// source: VodEditService
// DO NOT EDIT!

package vod

import (
        "encoding/json"
        "fmt"
        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
        "google.golang.org/protobuf/encoding/protojson"
        "testing"
)

func Test_SubmitDirectEditTaskSync(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // 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/65655.
        // 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.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        params, _ := json.Marshal(map[string]interface{}{})
        query := &request.VodSubmitDirectEditTaskSyncRequest{
                Uploader:    "your target store vod space",
                Application: "your application",
                EditParam:   params,
        }
        resp, status, err := instance.SubmitDirectEditTaskSync(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

取消剪辑任务

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

package vod

import (
        "encoding/json"
        "fmt"
        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
        "google.golang.org/protobuf/encoding/protojson"
        "testing"
)

func Test_CancelDirectEditTask(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // 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/65655.
        // 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.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodCancelDirectEditTaskRequest{
                ReqId: "your ReqId here",
        }
        resp, status, err := instance.CancelDirectEditTask(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

查询任务进度

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

package vod

import (
        "encoding/json"
        "fmt"
        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
        "google.golang.org/protobuf/encoding/protojson"
        "testing"
)

func Test_GetDirectEditProgress(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // 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/65655.
        // 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.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodGetDirectEditProgressRequest{
                ReqId: "your ReqId here",
        }

        resp, status, err := instance.GetDirectEditProgress(query)
        fmt.Println(status)
        fmt.Println(err)
        op := &protojson.MarshalOptions{
                EmitUnpopulated: true,
        }
        format := op.Format(resp)
        fmt.Println(format)
}

注意事项

返回结果 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
}

查询任务详情

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

package vod

import (
        "encoding/json"
        "fmt"
        "github.com/volcengine/volc-sdk-golang/base"
        "github.com/volcengine/volc-sdk-golang/service/vod"
        "github.com/volcengine/volc-sdk-golang/service/vod/models/request"
        "google.golang.org/protobuf/encoding/protojson"
        "testing"
)

func Test_GetDirectEditResult(t *testing.T) {
        // Create a VOD instance in the specified region.
        // instance := vod.NewInstanceWithRegion("cn-north-1")
        instance := vod.NewInstance()

        // 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/65655.
        // 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.
        // instance.SetCredential(base.Credentials{
        // AccessKeyID:     "your ak",
        // SecretAccessKey: "your sk",
        //})

        query := &request.VodGetDirectEditResultRequest{
                ReqIds: []string{"your ReqId here"},
        }

        resp, status, err := instance.GetDirectEditResult(query)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}