All Products
Search
Document Center

Video editing

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Produce videos based on a timeline

In most scenarios, you can use this method to produce videos. For more information about the request and response parameters, see ProduceEditingProjectVideo.

For more information about examples of producing videos based on a timeline, see Video editing: Examples.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

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

    // Constructs a timeline for producing videos. The following example 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)

    // Specifies the metadata of the produced video.
    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)

    // Specifies the production configuration.
    /*
    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)
}

Produce videos based on an online editing project

If online editing projects need to be managed with high requirements, you can use this method to produce videos. For more information about the request and response parameters, see ProduceEditingProjectVideo.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

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

    // Sets the ID of the online editing project.
    request.ProjectId = "<ProjectId>"

    // Specifies the metadata of the produced video.
    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)

    // Specifies the production configuration.
    /*
    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)
}

Create an online editing project

For more information about the request and response parameters, see AddEditingProject.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

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

    // Constructs a timeline of the online editing project. The following example 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)

    // Specifies the metadata of the online editing project.
    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)
}

Modify an online editing project

For more information about the request and response parameters, see UpdateEditingProject.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    "encoding/json"
    "fmt"
)

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

    // Sets the ID of the online editing project.
    request.ProjectId = "<ProjectId>"

    // Constructs a timeline of the online editing project. The following example 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)

    // Specifies the metadata of the online editing project.
    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)
}

Delete one or more online editing projects

For more information about the request and response parameters, see DeleteEditingProject.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/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)
}

Obtain the information about an online editing project

For more information about the request and response parameters, see GetEditingProject.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/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)
}

Search for online editing projects

For more information about the request and response parameters, see SearchEditingProject.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/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)
    }
}

Set materials to be edited for an online editing project

For more information about the request and response parameters, see SetEditingProjectMaterials.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/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>"
    // Specifies the material IDs for the online editing project. Separate multiple material IDs with a comma (,). A material ID is a media asset ID specified by parameters such as VideoId, ImageId, or 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)
}

Obtain a list of materials to be edited for an online editing project

For more information about the request and response parameters, see GetEditingProjectMaterials.

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
    "github.com/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)
    }
}