全部产品
云市场

视频剪辑

更新时间:2019-01-02 12:04:33

初始化客户端

使用前请先初始化客户端,参考 InitVodClient 接口。

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

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

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

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func ProduceEditingVideoByTimeline(client *vod.Client) (response *vod.ProduceEditingProjectVideoResponse, err error) {
  10. request := vod.CreateProduceEditingProjectVideoRequest()
  11. // set timeline, this sample shows how to merge two videos
  12. videoTrackClips := []map[string]interface{}{}
  13. videoTrackClip1 := map[string]interface{}{"MediaId": "<VideoId1>"}
  14. videoTrackClip2 := map[string]interface{}{"MediaId": "<VideoId2>"}
  15. videoTrackClips = append(videoTrackClips, videoTrackClip1, videoTrackClip2)
  16. videoTrack := map[string]interface{}{"VideoTrackClips": videoTrackClips}
  17. videoTracks := []map[string]interface{}{}
  18. videoTracks = append(videoTracks, videoTrack)
  19. timeline := map[string]interface{}{"VideoTracks": videoTracks}
  20. jsonTimeline, err := json.Marshal(timeline)
  21. if err != nil {
  22. fmt.Println("json.Marshal failed:", err)
  23. return
  24. }
  25. request.Timeline = string(jsonTimeline)
  26. // set media metadata
  27. mediaMetadata := map[string]interface{}{"Title": "editing sample title", "Description": "editing sample description",
  28. "Tags": "Tag1,Tag2"}
  29. jsonMeta, err := json.Marshal(mediaMetadata)
  30. if err != nil {
  31. fmt.Println("json.Marshal failed:", err)
  32. return
  33. }
  34. request.MediaMetadata = string(jsonMeta)
  35. // set produce config
  36. /*
  37. produceConfig := map[string]interface{}{"TemplateGroupId": "<templateGroupId>"}
  38. jsonConfig, err := json.Marshal(produceConfig)
  39. if err != nil {
  40. fmt.Println("json.Marshal failed:", err)
  41. return
  42. }
  43. request.ProduceConfig = string(jsonConfig)
  44. */
  45. request.AcceptFormat = "JSON"
  46. return client.ProduceEditingProjectVideo(request)
  47. }
  48. func main() {
  49. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  50. if err != nil {
  51. panic(err)
  52. }
  53. response, err := ProduceEditingVideoByTimeline(client)
  54. if err != nil {
  55. panic(err)
  56. }
  57. fmt.Println(response.GetHttpContentString())
  58. fmt.Println(response.RequestId)
  59. fmt.Println(response.MediaId)
  60. }

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

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

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func ProduceEditingVideoByProject(client *vod.Client) (response *vod.ProduceEditingProjectVideoResponse, err error) {
  10. request := vod.CreateProduceEditingProjectVideoRequest()
  11. // set ProjectId
  12. request.ProjectId = "<ProjectId>"
  13. // set media metadata
  14. mediaMetadata := map[string]interface{}{"Title": "editing sample title", "Description": "editing sample description",
  15. "Tags": "Tag1,Tag2"}
  16. jsonMeta, err := json.Marshal(mediaMetadata)
  17. if err != nil {
  18. fmt.Println("json.Marshal failed:", err)
  19. return
  20. }
  21. request.MediaMetadata = string(jsonMeta)
  22. // set produce config
  23. /*
  24. produceConfig := map[string]interface{}{"TemplateGroupId": "<templateGroupId>"}
  25. jsonConfig, err := json.Marshal(produceConfig)
  26. if err != nil {
  27. fmt.Println("json.Marshal failed:", err)
  28. return
  29. }
  30. request.ProduceConfig = string(jsonConfig)
  31. */
  32. request.AcceptFormat = "JSON"
  33. return client.ProduceEditingProjectVideo(request)
  34. }
  35. func main() {
  36. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  37. if err != nil {
  38. panic(err)
  39. }
  40. response, err := ProduceEditingVideoByProject(client)
  41. if err != nil {
  42. panic(err)
  43. }
  44. fmt.Println(response.GetHttpContentString())
  45. fmt.Println(response.RequestId)
  46. fmt.Println(response.MediaId)
  47. }

创建云剪辑工程

接口参数和返回字段请参考 AddEditingProject

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyAddEditingProject(client *vod.Client) (response *vod.AddEditingProjectResponse, err error) {
  10. request := vod.CreateAddEditingProjectRequest()
  11. // set timeline, this sample shows how to merge two videos
  12. videoTrackClips := []map[string]interface{}{}
  13. videoTrackClip1 := map[string]interface{}{"MediaId": "<VideoId1>"}
  14. videoTrackClip2 := map[string]interface{}{"MediaId": "<VideoId2>"}
  15. videoTrackClips = append(videoTrackClips, videoTrackClip1, videoTrackClip2)
  16. videoTrack := map[string]interface{}{"VideoTrackClips": videoTrackClips}
  17. videoTracks := []map[string]interface{}{}
  18. videoTracks = append(videoTracks, videoTrack)
  19. timeline := map[string]interface{}{"VideoTracks": videoTracks}
  20. jsonTimeline, err := json.Marshal(timeline)
  21. if err != nil {
  22. fmt.Println("json.Marshal failed:", err)
  23. return
  24. }
  25. request.Timeline = string(jsonTimeline)
  26. // set project metadata
  27. request.Title = "editing project title"
  28. request.Description = "editing project description"
  29. request.AcceptFormat = "JSON"
  30. return client.AddEditingProject(request)
  31. }
  32. func main() {
  33. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  34. if err != nil {
  35. panic(err)
  36. }
  37. response, err := MyAddEditingProject(client)
  38. if err != nil {
  39. panic(err)
  40. }
  41. fmt.Println(response.GetHttpContentString())
  42. fmt.Println(response.RequestId)
  43. fmt.Println(response.Project.ProjectId)
  44. }

修改云剪辑工程

接口参数和返回字段请参考 UpdateEditingProject

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "encoding/json"
  7. "fmt"
  8. )
  9. func MyUpdateEditingProject(client *vod.Client) (response *vod.UpdateEditingProjectResponse, err error) {
  10. request := vod.CreateUpdateEditingProjectRequest()
  11. // set projectId
  12. request.ProjectId = "<ProjectId>"
  13. // set timeline, this sample shows how to merge two videos
  14. videoTrackClips := []map[string]interface{}{}
  15. videoTrackClip1 := map[string]interface{}{"MediaId": "<VideoId1>"}
  16. videoTrackClip2 := map[string]interface{}{"MediaId": "<VideoId2>"}
  17. videoTrackClips = append(videoTrackClips, videoTrackClip1, videoTrackClip2)
  18. videoTrack := map[string]interface{}{"VideoTrackClips": videoTrackClips}
  19. videoTracks := []map[string]interface{}{}
  20. videoTracks = append(videoTracks, videoTrack)
  21. timeline := map[string]interface{}{"VideoTracks": videoTracks}
  22. jsonTimeline, err := json.Marshal(timeline)
  23. if err != nil {
  24. fmt.Println("json.Marshal failed:", err)
  25. return
  26. }
  27. request.Timeline = string(jsonTimeline)
  28. // set project metadata
  29. request.Title = "new editing project title"
  30. request.Description = "new editing project description"
  31. request.AcceptFormat = "JSON"
  32. return client.UpdateEditingProject(request)
  33. }
  34. func main() {
  35. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  36. if err != nil {
  37. panic(err)
  38. }
  39. response, err := MyUpdateEditingProject(client)
  40. if err != nil {
  41. panic(err)
  42. }
  43. fmt.Println(response.GetHttpContentString())
  44. fmt.Println(response.RequestId)
  45. }

删除云剪辑工程

接口参数和返回字段请参考 DeleteEditingProject

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyDeleteEditingProject(client *vod.Client) (response *vod.DeleteEditingProjectResponse, err error) {
  9. request := vod.CreateDeleteEditingProjectRequest()
  10. request.ProjectIds = "ProjectId1,ProjectId2"
  11. request.AcceptFormat = "JSON"
  12. return client.DeleteEditingProject(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyDeleteEditingProject(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.RequestId)
  25. }

获取单个云剪辑工程

接口参数和返回字段请参考 GetEditingProject

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetEditingProject(client *vod.Client) (response *vod.GetEditingProjectResponse, err error) {
  9. request := vod.CreateGetEditingProjectRequest()
  10. request.ProjectId = "<ProjectId>"
  11. request.AcceptFormat = "JSON"
  12. return client.GetEditingProject(request)
  13. }
  14. func main() {
  15. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  16. if err != nil {
  17. panic(err)
  18. }
  19. response, err := MyGetEditingProject(client)
  20. if err != nil {
  21. panic(err)
  22. }
  23. fmt.Println(response.GetHttpContentString())
  24. fmt.Println(response.RequestId)
  25. fmt.Printf("%s: %s\n", response.Project.Title, response.Project.Timeline)
  26. }

搜索云剪辑工程

接口参数和返回字段请参考 SearchEditingProject

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MySearchEditingProject(client *vod.Client) (response *vod.SearchEditingProjectResponse, err error) {
  9. request := vod.CreateSearchEditingProjectRequest()
  10. request.Title = "<Title Keywords>"
  11. request.StartTime = "2018-10-11T12:00:00Z"
  12. request.EndTime = "2018-12-25T12:00:00Z"
  13. request.PageNo = "1"
  14. request.PageSize = "10"
  15. request.AcceptFormat = "JSON"
  16. return client.SearchEditingProject(request)
  17. }
  18. func main() {
  19. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  20. if err != nil {
  21. panic(err)
  22. }
  23. response, err := MySearchEditingProject(client)
  24. if err != nil {
  25. panic(err)
  26. }
  27. fmt.Println(response.GetHttpContentString())
  28. fmt.Println(response.RequestId)
  29. for _, project := range response.ProjectList.Project {
  30. fmt.Printf("%s: %s\n", project.ProjectId, project.Title)
  31. }
  32. }

设置云剪辑工程素材

接口参数和返回字段请参考 SetEditingProjectMaterials

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MySetEditingProjectMaterials(client *vod.Client) (response *vod.SetEditingProjectMaterialsResponse, err error) {
  9. request := vod.CreateSetEditingProjectMaterialsRequest()
  10. request.ProjectId = "<ProjectId>"
  11. // 设置素材ID,多个用逗号分隔。素材ID即媒资ID,如视频VideoId、图片ImageId、辅助媒资MediaId等。
  12. request.MaterialIds = "VideoId,ImageId"
  13. request.AcceptFormat = "JSON"
  14. return client.SetEditingProjectMaterials(request)
  15. }
  16. func main() {
  17. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  18. if err != nil {
  19. panic(err)
  20. }
  21. response, err := MySetEditingProjectMaterials(client)
  22. if err != nil {
  23. panic(err)
  24. }
  25. fmt.Println(response.GetHttpContentString())
  26. fmt.Println(response.RequestId)
  27. }

获取云剪辑工程素材

接口参数和返回字段请参考 GetEditingProjectMaterials

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/sdk"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/vod"
  5. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  6. "fmt"
  7. )
  8. func MyGetEditingProjectMaterials(client *vod.Client) (response *vod.GetEditingProjectMaterialsResponse, err error) {
  9. request := vod.CreateGetEditingProjectMaterialsRequest()
  10. request.ProjectId = "<ProjectId>"
  11. request.Type = "video"
  12. request.AcceptFormat = "JSON"
  13. return client.GetEditingProjectMaterials(request)
  14. }
  15. func main() {
  16. client, err := InitVodClient("<accessKeyId>", "<accessKeySecret>")
  17. if err != nil {
  18. panic(err)
  19. }
  20. response, err := MyGetEditingProjectMaterials(client)
  21. if err != nil {
  22. panic(err)
  23. }
  24. fmt.Println(response.GetHttpContentString())
  25. fmt.Println(response.RequestId)
  26. for _, material := range response.MaterialList.Material {
  27. fmt.Printf("%s: %s\n", material.MaterialId, material.Title)
  28. }
  29. }