全部产品
云市场

视频剪辑

更新时间:2019-01-24 12:38:07

初始化客户端

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

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

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

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. using Newtonsoft.Json.Linq;
  6. namespace Aliyun.Acs.vod.Sdk.ProduceEditingProjectVideo
  7. {
  8. class MainClass
  9. {
  10. /// <summary>
  11. /// The entry point of the program, where the program control starts and ends.
  12. /// </summary>
  13. /// <param name="args">The command-line arguments.</param>
  14. public static void Main(string[] args)
  15. {
  16. try
  17. {
  18. // 构造请求
  19. ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
  20. // 构造剪辑工程时间线
  21. request.Timeline = BuildTimeline();
  22. // 设置元数据
  23. request.MediaMetadata = BuildMediaMetadata();
  24. // 设置工程配置
  25. request.ProduceConfig = BuildProduceConfig();
  26. // 初始化客户端
  27. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  28. // 发起请求,并得到 response
  29. ProduceEditingProjectVideoResponse response = client.GetAcsResponse(request);
  30. Console.WriteLine("RequestId = " + response.RequestId);
  31. Console.WriteLine("MediaId = " + response.MediaId);
  32. Console.WriteLine("ProjectId = " + response.ProjectId);
  33. }
  34. catch (ServerException e)
  35. {
  36. if (e.RequestId != null)
  37. {
  38. Console.WriteLine("RequestId = " + e.RequestId);
  39. }
  40. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  41. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  42. }
  43. catch (ClientException e)
  44. {
  45. if (e.RequestId != null)
  46. {
  47. Console.WriteLine("RequestId = " + e.RequestId);
  48. }
  49. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  50. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  51. }
  52. catch (Exception e)
  53. {
  54. Console.WriteLine("ErrorMessage = " + e.ToString());
  55. }
  56. }
  57. /// <summary>
  58. /// Builds the timeline.
  59. /// </summary>
  60. /// <returns>The timeline.</returns>
  61. private static string BuildTimeline() {
  62. JObject timeLine = new JObject();
  63. // Video Track
  64. JArray videoTracks = new JArray();
  65. JObject videoTrack = new JObject();
  66. // Video Track Clips
  67. JArray videoTrackClips = new JArray();
  68. JObject videoTrackClip1 = new JObject();
  69. videoTrackClip1.Add("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
  70. videoTrackClips.Add(videoTrackClip1);
  71. JObject videoTrackClip2 = new JObject();
  72. videoTrackClip2.Add("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
  73. videoTrackClips.Add(videoTrackClip2);
  74. videoTrack.Add("VideoTrackClips", videoTrackClips);
  75. videoTracks.Add(videoTrack);
  76. timeLine.Add("VideoTracks", videoTracks);
  77. return timeLine.ToString();
  78. }
  79. /// <summary>
  80. /// Builds the media metadata.
  81. /// </summary>
  82. /// <returns>The media metadata.</returns>
  83. private static string BuildMediaMetadata() {
  84. JObject mediaMetadata = new JObject();
  85. // Produce Media Title
  86. mediaMetadata.Add("Title", "Title");
  87. // Produce Media Description
  88. mediaMetadata.Add("Description", "Description");
  89. // Produce Media UserDefined Cover URL
  90. mediaMetadata.Add("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
  91. // Produce Media Category ID
  92. mediaMetadata.Add("CateId", null);
  93. // Produce Media Category Name
  94. mediaMetadata.Add("Tags", "Tag1,Tag2,Test");
  95. return mediaMetadata.ToString();
  96. }
  97. /// <summary>
  98. /// Builds the produce config.
  99. /// </summary>
  100. /// <returns>The produce config.</returns>
  101. private static string BuildProduceConfig() {
  102. JObject produceConfig = new JObject();
  103. /**
  104. * The produce process can generate media mezzanine file. You can use the mezzanine file to transcode other media files,just like the transcode process after file upload finished. This field describe the Transocde TemplateGroup ID after produce mezzanine finished.
  105. * 1. Not required
  106. * 2. Use default transcode template group id when empty
  107. **/
  108. produceConfig.Add("TemplateGroupId", null);
  109. return produceConfig.ToString();
  110. }
  111. }
  112. }

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

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. using Newtonsoft.Json.Linq;
  7. namespace Aliyun.Acs.vod.Sdk.ProduceEditingProjectVideoProjectId
  8. {
  9. class MainClass
  10. {
  11. /// <summary>
  12. /// The entry point of the program, where the program control starts and ends.
  13. /// </summary>
  14. /// <param name="args">The command-line arguments.</param>
  15. public static void Main(string[] args)
  16. {
  17. ProduceEditingProjectVideoResponse response = null;
  18. try
  19. {
  20. // 构造请求
  21. ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
  22. // 构造剪辑工程时间线
  23. request.ProjectId = "ProjectId";
  24. // 设置元数据
  25. request.MediaMetadata = BuildMediaMetadata();
  26. // 设置工程配置
  27. request.ProduceConfig = BuildProduceConfig();
  28. // 初始化客户端
  29. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  30. // 发起请求,并得到 response
  31. response = client.GetAcsResponse(request);
  32. Console.WriteLine("RequestId = " + response.RequestId);
  33. Console.WriteLine("MediaId = " + response.MediaId);
  34. Console.WriteLine("ProjectId = " + response.ProjectId);
  35. }
  36. catch (ServerException e)
  37. {
  38. if (e.RequestId != null)
  39. {
  40. Console.WriteLine("RequestId = " + e.RequestId);
  41. }
  42. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  43. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  44. }
  45. catch (ClientException e)
  46. {
  47. if (e.RequestId != null)
  48. {
  49. Console.WriteLine("RequestId = " + e.RequestId);
  50. }
  51. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  52. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  53. }
  54. catch (Exception e)
  55. {
  56. Console.WriteLine("ErrorMessage = " + e.ToString());
  57. }
  58. }
  59. /// <summary>
  60. /// Builds the media metadata.
  61. /// </summary>
  62. /// <returns>The media metadata.</returns>
  63. private static string BuildMediaMetadata()
  64. {
  65. JObject mediaMetadata = new JObject();
  66. // Produce Media Title
  67. mediaMetadata.Add("Title", "Title");
  68. // Produce Media Description
  69. mediaMetadata.Add("Description", "Description");
  70. // Produce Media UserDefined Cover URL
  71. mediaMetadata.Add("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
  72. // Produce Media Category ID
  73. mediaMetadata.Add("CateId", null);
  74. // Produce Media Category Name
  75. mediaMetadata.Add("Tags", "Tag1,Tag2,Test");
  76. return mediaMetadata.ToString();
  77. }
  78. /// <summary>
  79. /// Builds the produce config.
  80. /// </summary>
  81. /// <returns>The produce config.</returns>
  82. private static string BuildProduceConfig()
  83. {
  84. JObject produceConfig = new JObject();
  85. /**
  86. * The produce process can generate media mezzanine file. You can use the mezzanine file to transcode other media files,just like the transcode process after file upload finished. This field describe the Transocde TemplateGroup ID after produce mezzanine finished.
  87. * 1. Not required
  88. * 2. Use default transcode template group id when empty
  89. **/
  90. produceConfig.Add("TemplateGroupId", null);
  91. return produceConfig.ToString();
  92. }
  93. }
  94. }

创建云剪辑工程

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.AddEditingProject
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. AddEditingProjectRequest request = new AddEditingProjectRequest();
  15. request.Description = "new Description";
  16. request.Title = "new Title";
  17. // 初始化客户端
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. AddEditingProjectResponse response = client.GetAcsResponse(request);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. if (response.Project != null) {
  23. Console.WriteLine("ProjectId = " + response.Project.ProjectId);
  24. Console.WriteLine("Title = " + response.Project.Title);
  25. }
  26. }
  27. catch (ServerException e)
  28. {
  29. if (e.RequestId != null)
  30. {
  31. Console.WriteLine("RequestId = " + e.RequestId);
  32. }
  33. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  34. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  35. }
  36. catch (ClientException e)
  37. {
  38. if (e.RequestId != null)
  39. {
  40. Console.WriteLine("RequestId = " + e.RequestId);
  41. }
  42. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  43. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  44. }
  45. catch (Exception e)
  46. {
  47. Console.WriteLine("ErrorMessage = " + e.ToString());
  48. }
  49. }
  50. }
  51. }

修改云剪辑工程

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.UpdateEditingProject
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. UpdateEditingProjectRequest request = new UpdateEditingProjectRequest();
  15. request.ProjectId = "YourProjectId";
  16. request.Title = "new Title";
  17. // 初始化客户端
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. UpdateEditingProjectResponse response = client.GetAcsResponse(request);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. }
  23. catch (ServerException e)
  24. {
  25. if (e.RequestId != null)
  26. {
  27. Console.WriteLine("RequestId = " + e.RequestId);
  28. }
  29. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  30. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  31. }
  32. catch (ClientException e)
  33. {
  34. if (e.RequestId != null)
  35. {
  36. Console.WriteLine("RequestId = " + e.RequestId);
  37. }
  38. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  39. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  40. }
  41. catch (Exception e)
  42. {
  43. Console.WriteLine("ErrorMessage = " + e.ToString());
  44. }
  45. }
  46. }
  47. }

删除云剪辑工程

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.Core.Profile;
  5. using Aliyun.Acs.vod.Model.V20170321;
  6. namespace Aliyun.Acs.vod.Sdk.DeleteEditingProject
  7. {
  8. class MainClass
  9. {
  10. public static void Main(string[] args)
  11. {
  12. try
  13. {
  14. // 构造请求
  15. DeleteEditingProjectRequest request = new DeleteEditingProjectRequest();
  16. // Use comma to split Multi Editing Project IDs
  17. request.ProjectIds = "projectid1,projectid2";
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. DeleteEditingProjectResponse response = client.GetAcsResponse(request);
  22. Console.WriteLine("RequestId = " + response.RequestId);
  23. }
  24. catch (ServerException e)
  25. {
  26. if (e.RequestId != null)
  27. {
  28. Console.WriteLine("RequestId = " + e.RequestId);
  29. }
  30. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  31. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  32. }
  33. catch (ClientException e)
  34. {
  35. if (e.RequestId != null)
  36. {
  37. Console.WriteLine("RequestId = " + e.RequestId);
  38. }
  39. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  40. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  41. }
  42. catch (Exception e)
  43. {
  44. Console.WriteLine("ErrorMessage = " + e.ToString());
  45. }
  46. }
  47. }
  48. }

获取单个云剪辑工程

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.GetEditingProject
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. GetEditingProjectRequest request = new GetEditingProjectRequest();
  15. request.ProjectId = "projectid";
  16. // 初始化客户端
  17. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. // 发起请求,并得到 response
  19. GetEditingProjectResponse response = client.GetAcsResponse(request);
  20. Console.WriteLine("RequestId = " + response.RequestId);
  21. if (response.Project != null)
  22. {
  23. Console.WriteLine("ProjectId = " + response.Project.ProjectId);
  24. Console.WriteLine("Title = " + response.Project.Title);
  25. }
  26. }
  27. catch (ServerException e)
  28. {
  29. if (e.RequestId != null)
  30. {
  31. Console.WriteLine("RequestId = " + e.RequestId);
  32. }
  33. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  34. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  35. }
  36. catch (ClientException e)
  37. {
  38. if (e.RequestId != null)
  39. {
  40. Console.WriteLine("RequestId = " + e.RequestId);
  41. }
  42. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  43. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  44. }
  45. catch (Exception e)
  46. {
  47. Console.WriteLine("ErrorMessage = " + e.ToString());
  48. }
  49. }
  50. }
  51. }

搜索云剪辑工程

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.SearchEditingProject
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. SearchEditingProjectRequest request = new SearchEditingProjectRequest();
  15. request.Title = "Title Keywords";
  16. request.StartTime = "2017-01-11T12:00:00Z";
  17. request.EndTime = "2017-01-12T12:00:00Z";
  18. request.PageSize = 10;
  19. request.PageNo = 1;
  20. // 初始化客户端
  21. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  22. // 发起请求,并得到 response
  23. SearchEditingProjectResponse response = client.GetAcsResponse(request);
  24. // 打印本次请求ID
  25. Console.WriteLine("RequestId = " + response.RequestId);
  26. if (response.ProjectList != null && response.ProjectList.Count > 0)
  27. {
  28. foreach (var project in response.ProjectList)
  29. {
  30. Console.WriteLine("ProjectId = " + project.ProjectId);
  31. }
  32. }
  33. }
  34. catch (ServerException e)
  35. {
  36. if (e.RequestId != null)
  37. {
  38. Console.WriteLine("RequestId = " + e.RequestId);
  39. }
  40. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  41. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  42. }
  43. catch (ClientException e)
  44. {
  45. if (e.RequestId != null)
  46. {
  47. Console.WriteLine("RequestId = " + e.RequestId);
  48. }
  49. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  50. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  51. }
  52. catch (Exception e)
  53. {
  54. Console.WriteLine("ErrorMessage = " + e.ToString());
  55. }
  56. }
  57. }
  58. }

设置云剪辑工程素材

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.SetEditingProjectMaterials
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. SetEditingProjectMaterialsRequest request = new SetEditingProjectMaterialsRequest();
  15. // Editing Project ID
  16. request.ProjectId = "projectid";
  17. // Set Editing Project Material IDs, use comma to split
  18. request.MaterialIds = "materialId1,materialId2";
  19. // 初始化客户端
  20. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  21. // 发起请求,并得到 response
  22. SetEditingProjectMaterialsResponse response = client.GetAcsResponse(request);
  23. // 打印本次请求ID
  24. Console.WriteLine("RequestId = " + response.RequestId);
  25. }
  26. catch (ServerException e)
  27. {
  28. if (e.RequestId != null)
  29. {
  30. Console.WriteLine("RequestId = " + e.RequestId);
  31. }
  32. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  33. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  34. }
  35. catch (ClientException e)
  36. {
  37. if (e.RequestId != null)
  38. {
  39. Console.WriteLine("RequestId = " + e.RequestId);
  40. }
  41. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  42. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  43. }
  44. catch (Exception e)
  45. {
  46. Console.WriteLine("ErrorMessage = " + e.ToString());
  47. }
  48. }
  49. }
  50. }

获取云剪辑工程素材

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. Aliyun.Acs.vod.Sdk.GetEditingProjectMaterials
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. GetEditingProjectMaterialsRequest request = new GetEditingProjectMaterialsRequest();
  15. request.ProjectId = "projectid";
  16. request.Type = "video";
  17. // 初始化客户端
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. GetEditingProjectMaterialsResponse response = client.GetAcsResponse(request);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. if (response.MaterialList != null && response.MaterialList.Count > 0)
  23. {
  24. foreach (var material in response.MaterialList)
  25. {
  26. Console.WriteLine("MaterialId = " + material.MaterialId);
  27. Console.WriteLine("Title = " + material.Title);
  28. }
  29. }
  30. }
  31. catch (ServerException e)
  32. {
  33. if (e.RequestId != null)
  34. {
  35. Console.WriteLine("RequestId = " + e.RequestId);
  36. }
  37. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  38. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  39. }
  40. catch (ClientException e)
  41. {
  42. if (e.RequestId != null)
  43. {
  44. Console.WriteLine("RequestId = " + e.RequestId);
  45. }
  46. Console.WriteLine("ErrorCode = " + e.ErrorCode);
  47. Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
  48. }
  49. catch (Exception e)
  50. {
  51. Console.WriteLine("ErrorMessage = " + e.ToString());
  52. }
  53. }
  54. }
  55. }