全部产品

视频剪辑

本篇文档提供了Go SDK视频剪辑模块相关功能的API调用示例。包含发起剪辑合成、创建云剪辑工程、修改云剪辑工程、删除云剪辑工程、获取单个云剪辑工程、设置云剪辑工程素材等。

初始化客户端

使用前请先初始化客户端,请参见初始化

通过时间线-发起剪辑合成

调用ProduceEditingProjectVideo接口,完成通过时间线-发起剪辑合成功能。

绝大多数场景下,使用这种方式即可合成视频。接口参数和返回字段请参见ProduceEditingProjectVideo。调用示例如下:

说明

通过时间线实现剪辑合成的更多Timeline示例请参见视频剪辑-使用示例

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func ProduceEditingVideoByTimeline(client *vod.Client) (response *vod.ProduceEditingProjectVideoResponse, err error) {
    request := vod.CreateProduceEditingProjectVideoRequest()

    // set timeline, this sample shows how to merge two videos
    videoTrackClips := []map[string]interface{}{}
    videoTrackClip1 := map[string]interface{}{"MediaId": "<VideoId1>"}
    videoTrackClip2 := map[string]interface{}{"MediaId": "<VideoId2>"}
    videoTrackClips = append(videoTrackClips, videoTrackClip1, videoTrackClip2)
    videoTrack := map[string]interface{}{"VideoTrackClips": videoTrackClips}
    videoTracks := []map[string]interface{}{}
    videoTracks = append(videoTracks, videoTrack)
    timeline := map[string]interface{}{"VideoTracks": videoTracks}
    jsonTimeline, err := json.Marshal(timeline)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.Timeline = string(jsonTimeline)

    // set media metadata
    mediaMetadata := map[string]interface{}{"Title": "editing sample title", "Description": "editing sample description",
        "Tags": "Tag1,Tag2"}
    jsonMeta, err := json.Marshal(mediaMetadata)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.MediaMetadata = string(jsonMeta)

    // set produce config
    /*
    produceConfig := map[string]interface{}{"TemplateGroupId": "<templateGroupId>"}
    jsonConfig, err := json.Marshal(produceConfig)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.ProduceConfig = string(jsonConfig)
    */

    request.AcceptFormat = "JSON"

    return client.ProduceEditingProjectVideo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := ProduceEditingVideoByTimeline(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.MediaId)
}

通过云剪辑工程-发起剪辑合成

调用ProduceEditingProjectVideo接口,完成通过云剪辑工程-发起剪辑合成功能。

对云剪辑工程有较高管理需求的场景下,可以使用这种方式合成视频。接口参数和返回字段请参见ProduceEditingProjectVideo。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func ProduceEditingVideoByProject(client *vod.Client) (response *vod.ProduceEditingProjectVideoResponse, err error) {
    request := vod.CreateProduceEditingProjectVideoRequest()

    // set ProjectId
    request.ProjectId = "<ProjectId>"

    // set media metadata
    mediaMetadata := map[string]interface{}{"Title": "editing sample title", "Description": "editing sample description",
        "Tags": "Tag1,Tag2"}
    jsonMeta, err := json.Marshal(mediaMetadata)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.MediaMetadata = string(jsonMeta)

    // set produce config
    /*
    produceConfig := map[string]interface{}{"TemplateGroupId": "<templateGroupId>"}
    jsonConfig, err := json.Marshal(produceConfig)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.ProduceConfig = string(jsonConfig)
    */

    request.AcceptFormat = "JSON"

    return client.ProduceEditingProjectVideo(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := ProduceEditingVideoByProject(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.MediaId)
}

创建云剪辑工程

调用AddEditingProject接口,完成创建云剪辑工程功能。

接口参数和返回字段请参见AddEditingProject。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyAddEditingProject(client *vod.Client) (response *vod.AddEditingProjectResponse, err error) {
    request := vod.CreateAddEditingProjectRequest()

    // set timeline, this sample shows how to merge two videos
    videoTrackClips := []map[string]interface{}{}
    videoTrackClip1 := map[string]interface{}{"MediaId": "<VideoId1>"}
    videoTrackClip2 := map[string]interface{}{"MediaId": "<VideoId2>"}
    videoTrackClips = append(videoTrackClips, videoTrackClip1, videoTrackClip2)
    videoTrack := map[string]interface{}{"VideoTrackClips": videoTrackClips}
    videoTracks := []map[string]interface{}{}
    videoTracks = append(videoTracks, videoTrack)
    timeline := map[string]interface{}{"VideoTracks": videoTracks}
    jsonTimeline, err := json.Marshal(timeline)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.Timeline = string(jsonTimeline)

    // set project metadata
    request.Title = "editing project title"
    request.Description = "editing project description"

    request.AcceptFormat = "JSON"

    return client.AddEditingProject(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyAddEditingProject(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Println(response.Project.ProjectId)
}

修改云剪辑工程

调用UpdateEditingProject接口,完成修改云剪辑工程功能。

接口参数和返回字段请参见UpdateEditingProject。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

func MyUpdateEditingProject(client *vod.Client) (response *vod.UpdateEditingProjectResponse, err error) {
    request := vod.CreateUpdateEditingProjectRequest()

    // set projectId
    request.ProjectId = "<ProjectId>"

    // set timeline, this sample shows how to merge two videos
    videoTrackClips := []map[string]interface{}{}
    videoTrackClip1 := map[string]interface{}{"MediaId": "<VideoId1>"}
    videoTrackClip2 := map[string]interface{}{"MediaId": "<VideoId2>"}
    videoTrackClips = append(videoTrackClips, videoTrackClip1, videoTrackClip2)
    videoTrack := map[string]interface{}{"VideoTrackClips": videoTrackClips}
    videoTracks := []map[string]interface{}{}
    videoTracks = append(videoTracks, videoTrack)
    timeline := map[string]interface{}{"VideoTracks": videoTracks}
    jsonTimeline, err := json.Marshal(timeline)
    if err != nil {
        fmt.Println("json.Marshal failed:", err)
        return
    }
    request.Timeline = string(jsonTimeline)

    // set project metadata
    request.Title = "new editing project title"
    request.Description = "new editing project description"

    request.AcceptFormat = "JSON"

    return client.UpdateEditingProject(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyUpdateEditingProject(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

删除云剪辑工程

调用DeleteEditingProject接口,完成删除云剪辑工程功能。

接口参数和返回字段请参见DeleteEditingProject。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyDeleteEditingProject(client *vod.Client) (response *vod.DeleteEditingProjectResponse, err error) {
    request := vod.CreateDeleteEditingProjectRequest()
    request.ProjectIds = "ProjectId1,ProjectId2"

    request.AcceptFormat = "JSON"

    return client.DeleteEditingProject(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyDeleteEditingProject(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

获取单个云剪辑工程

调用GetEditingProject接口,完成获取单个云剪辑工程功能。

接口参数和返回字段请参见GetEditingProject。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetEditingProject(client *vod.Client) (response *vod.GetEditingProjectResponse, err error) {
    request := vod.CreateGetEditingProjectRequest()
    request.ProjectId = "<ProjectId>"

    request.AcceptFormat = "JSON"

    return client.GetEditingProject(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetEditingProject(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    fmt.Printf("%s: %s\n", response.Project.Title, response.Project.Timeline)
}

搜索云剪辑工程

调用SearchEditingProject接口,完成搜索云剪辑工程功能。

接口参数和返回字段请参见SearchEditingProject。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MySearchEditingProject(client *vod.Client) (response *vod.SearchEditingProjectResponse, err error) {
    request := vod.CreateSearchEditingProjectRequest()
    request.Title = "<Title Keywords>"
    request.StartTime = "2018-10-11T12:00:00Z"
    request.EndTime =  "2018-12-25T12:00:00Z"
    request.PageNo = "1"
    request.PageSize = "10"

    request.AcceptFormat = "JSON"

    return client.SearchEditingProject(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MySearchEditingProject(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    for _, project := range response.ProjectList.Project {
        fmt.Printf("%s: %s\n", project.ProjectId, project.Title)
    }
}

设置云剪辑工程素材

调用SetEditingProjectMaterials接口,完成设置云剪辑工程素材功能。

接口参数和返回字段请参见SetEditingProjectMaterials。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MySetEditingProjectMaterials(client *vod.Client) (response *vod.SetEditingProjectMaterialsResponse, err error) {
    request := vod.CreateSetEditingProjectMaterialsRequest()
    request.ProjectId = "<ProjectId>"
    // 设置素材ID,多个用逗号分隔。素材ID即媒资ID,如视频VideoId、图片ImageId、辅助媒资MediaId等。
    request.MaterialIds = "VideoId,ImageId"

    request.AcceptFormat = "JSON"

    return client.SetEditingProjectMaterials(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MySetEditingProjectMaterials(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
}

获取云剪辑工程素材

调用GetEditingProjectMaterials接口,完成获取云剪辑工程素材功能。

接口参数和返回字段请参见GetEditingProjectMaterials。调用示例如下:

package main

import (
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/services/vod"
    "192.168.0.0/16/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "fmt"
)

func MyGetEditingProjectMaterials(client *vod.Client) (response *vod.GetEditingProjectMaterialsResponse, err error) {
    request := vod.CreateGetEditingProjectMaterialsRequest()
    request.ProjectId = "<ProjectId>"
    request.Type = "video"

    request.AcceptFormat = "JSON"

    return client.GetEditingProjectMaterials(request)
}

func main() {
    client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
    if err != nil {
        panic(err)
    }

    response, err := MyGetEditingProjectMaterials(client)
    if err != nil {
        panic(err)
    }

    fmt.Println(response.GetHttpContentString())
    fmt.Println(response.RequestId)
    for _, material := range response.MaterialList.Material {
        fmt.Printf("%s: %s\n", material.MaterialId, material.Title)
    }
}