You need to enable JavaScript to run this app.
导航

视频剪辑

最近更新时间2023.10.16 21:07:12

首次发布时间2022.07.08 19:20:13

本文为您提供了服务端 Go SDK 的视频剪辑模块相关的 API 调用示例。主要包含:提交编辑任务、查询任务详情等。

初始化

使用前请先完成初始化

提交剪辑任务

接口请求参数和返回参数详见 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) {
        instance := vod.NewInstance()
        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:查询任务进度

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) {
        instance := vod.NewInstance()
        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) {
        instance := vod.NewInstance()
        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)
        //获取EditParam中的Track
        for _, result := range resp.GetResult() {
                editParam := result.GetEditParam()
                tracks := editParam.GetTrack()
                for _, track := range tracks {
                        listValue := track.GetListValue()
                        for _, value := range listValue.Values {
                                structValue := value.GetStructValue()
                                fields := structValue.GetFields()
                                fmt.Println("ID:", fields["ID"].GetStringValue())
                                for _, value := range fields["TargetTime"].GetListValue().Values {
                                        fmt.Println(value.GetNumberValue())
                                }
                        }
                }
        }
        fmt.Println(resp.String())
}