You need to enable JavaScript to run this app.
文档中心
复制全文
下载 pdf
Go SDK
媒体处理任务
复制全文
下载 pdf
媒体处理任务

本文为您提供了服务端 Go SDK 的媒体处理任务相关的 API 调用示例。

初始化

使用前请先完成初始化,请参考初始化

提交媒体处理任务

接口请求参数和返回参数详见 OpenAPI:提交媒体处理任务

示例一:根据工作流模板触发任务

package main

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/service/imp"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/business"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/request"
)

func TestImp_SubmitJob(t *testing.T) {
        impService := imp.NewInstance()

        // call below method if you don't set ak and sk in $HOME/.vcloud/config
        impService.SetAccessKey("your AK")
        impService.SetSecretKey("your SK")

        // SubmitJob
        req := &request.ImpSubmitJobRequest{
                InputPath: &business.InputPath{
                        Type:         "VOD", // 素材库:VODMaterial 视频库:VOD
                        VodSpaceName: "your vod space",
                        FileId:       "your file id",
                },
                TemplateId:        "your template id",
                CallbackArgs:      "your callback args",
                EnableLowPriority: "false", // true开启 false 不开启 闲时转码模式
                Params:            nil,
        }

        resp, status, err := impService.SubmitJob(req)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

示例二:单任务触发

package main

import (
        "fmt"
        "testing"

        "github.com/volcengine/volc-sdk-golang/service/imp"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/business"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/request"
)

func TestImp_SubmitJobByJob(t *testing.T) {
        impService := imp.NewInstance()

        // call below method if you don't set ak and sk in $HOME/.vcloud/config
        impService.SetAccessKey("your AK")
        impService.SetSecretKey("your SK")

        // SubmitJob
        req := &request.ImpSubmitJobRequest{
                InputPath: &business.InputPath{
                        Type:         "VOD", // 素材库:VODMaterial 视频库:VOD
                        VodSpaceName: "your vod space",
                        FileId:       "your file id",
                },
                OutputPath: &business.OutputPath{
                        Type:         "VOD",
                        VodSpaceName: "your vod space",
                },
                Job: &business.Job{
                        TranscodeVideo: &business.TranscodeVideoJob{
                                Container: "your container",
                                Video: &business.Video{
                                        Codec: "your video codec",
                                },
                                Audio: &business.Audio{
                                        Codec: "your audio codec",
                                },
                        },
                },
                CallbackArgs:      "your callback args",
                EnableLowPriority: "false", // true开启 false 不开启 闲时转码模式
        }

        resp, status, err := impService.SubmitJob(req)
        fmt.Println(status)
        fmt.Println(err)
        fmt.Println(resp.String())
}

查询媒体处理任务

接口请求参数和返回参数详见 OpenAPI:查询媒体处理任务

package main

import (
        "log"
        "net/http"
        "testing"

        "github.com/stretchr/testify/assert"
        "github.com/volcengine/volc-sdk-golang/service/imp"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/business"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/request"
)

func TestImp_RetrieveJob(t *testing.T) {
        impService := imp.NewInstance()

        // call below method if you don't set ak and sk in $HOME/.vcloud/config

        impService.SetAccessKey("your AK")
        impService.SetSecretKey("your SK")

        // RetrieveJob
        req := &request.ImpRetrieveJobRequest{
                JobIds: []string{
                        "your job 1",
                        "your job 2",
                },
        }

        resp, status, err := impService.RetrieveJob(req)
        assert.NoError(t, err)
        assert.Equal(t, status, http.StatusOK)
        assert.NotNil(t, resp)
        assert.Equal(t, 2, len(resp.Result))

        log.Println(resp.Result)
}

取消媒体处理任务

接口请求参数和返回参数详见 OpenAPI:取消媒体处理任务

package main

import (
        "log"
        "net/http"
        "testing"

        "github.com/stretchr/testify/assert"
        "github.com/volcengine/volc-sdk-golang/service/imp"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/business"
        "github.com/volcengine/volc-sdk-golang/service/imp/models/request"
)

func TestImp_KillJob(t *testing.T) {
        impService := imp.NewInstance()

        // call below method if you don't set ak and sk in $HOME/.vcloud/config
        impService.SetAccessKey("your AK")
        impService.SetSecretKey("your SK")

        // KillJob
        req := &request.ImpKillJobRequest{
                JobId: "your job id",
        }

        resp, status, err := impService.KillJob(req)
        assert.NoError(t, err)
        assert.Equal(t, status, http.StatusOK)
        assert.NotNil(t, resp)
}
最近更新时间:2025.02.18 16:08:41
这个页面对您有帮助吗?
有用
有用
无用
无用