全部产品
云市场

视频剪辑

更新时间:2018-12-28 14:22:41

初始化客户端

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

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

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

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

  1. import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoRequest;
  2. import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
  9. // Build Editing Project Timeline
  10. request.setTimeline(buildTimeline());
  11. // Set Produce Media Metadata
  12. request.setMediaMetadata(buildMediaMetadata());
  13. // Set Produce Configuration
  14. request.setProduceConfig(buildProduceConfig());
  15. ProduceEditingProjectVideoResponse response = null;
  16. try {
  17. response = client.getAcsResponse(request);
  18. if (response != null){
  19. // Produce Media ID
  20. System.out.println("MediaId:" + response.getMediaId());
  21. // Request ID
  22. System.out.println("RequestId:" + response.getRequestId());
  23. }
  24. } catch (ServerException e){
  25. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  26. } catch (ClientException e){
  27. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  28. } catch (Exception e) {
  29. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  30. }
  31. }
  32. public static String buildMediaMetadata(){
  33. JSONObject mediaMetadata = new JSONObject();
  34. // Produce Media Title
  35. mediaMetadata.put("Title", "Title");
  36. // Produce Media Description
  37. mediaMetadata.put("Description", "Description");
  38. // Produce Media UserDefined Cover URL
  39. mediaMetadata.put("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
  40. // Produce Media Category ID
  41. mediaMetadata.put("CateId", null);
  42. // Produce Media Category Name
  43. mediaMetadata.put("Tags", "Tag1,Tag2,Test");
  44. return mediaMetadata.toString();
  45. }
  46. public static String buildProduceConfig(){
  47. JSONObject produceConfig = new JSONObject();
  48. /*
  49. 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.
  50. 1. Not required
  51. 2. Use default transcode template group id when empty
  52. */
  53. produceConfig.put("TemplateGroupId", null);
  54. return produceConfig.toString();
  55. }
  56. /**
  57. * This Sample shows how to merge two videos
  58. */
  59. public static String buildTimeline(){
  60. JSONObject timeline = new JSONObject();
  61. // Video Track
  62. JSONArray videoTracks = new JSONArray();
  63. JSONObject videoTrack = new JSONObject();
  64. // Video Track Clips
  65. JSONArray videoTrackClips = new JSONArray();
  66. JSONObject videoTrackClip1 = new JSONObject();
  67. videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
  68. videoTrackClips.add(videoTrackClip1);
  69. JSONObject videoTrackClip2 = new JSONObject();
  70. videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
  71. videoTrackClips.add(videoTrackClip2);
  72. videoTrack.put("VideoTrackClips", videoTrackClips);
  73. videoTracks.add(videoTrack);
  74. timeline.put("VideoTracks", videoTracks);
  75. return timeline.toString();
  76. }

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

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

  1. import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoRequest;
  2. import com.aliyuncs.vod.model.v20170321.ProduceEditingProjectVideoResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  8. ProduceEditingProjectVideoRequest request = new ProduceEditingProjectVideoRequest();
  9. // Set Editing Project ID need to produce
  10. request.setProjectId("ProjectId");
  11. // Set Produce Media Metadata
  12. request.setMediaMetadata(buildMediaMetadata());
  13. // Set Produce Configuration
  14. request.setProduceConfig(buildProduceConfig());
  15. ProduceEditingProjectVideoResponse response = null;
  16. try {
  17. response = client.getAcsResponse(request);
  18. if (response != null){
  19. // Produce Media ID
  20. System.out.println("MediaId:" + response.getMediaId());
  21. // Request ID
  22. System.out.println("RequestId:" + response.getRequestId());
  23. }
  24. } catch (ServerException e){
  25. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  26. } catch (ClientException e){
  27. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  28. } catch (Exception e) {
  29. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  30. }
  31. }
  32. public static String buildMediaMetadata(){
  33. JSONObject mediaMetadata = new JSONObject();
  34. // Produce Media Title
  35. mediaMetadata.put("Title", "Title");
  36. // Produce Media Description
  37. mediaMetadata.put("Description", "Description");
  38. // Produce Media UserDefined Cover URL
  39. mediaMetadata.put("CoverURL", "http://test.testvod123.com/media/cover/mediaid.jpg");
  40. // Produce Media Category ID
  41. mediaMetadata.put("CateId", null);
  42. // Produce Media Category Name
  43. mediaMetadata.put("Tags", "Tag1,Tag2,Test");
  44. return mediaMetadata.toString();
  45. }
  46. public static String buildProduceConfig(){
  47. JSONObject produceConfig = new JSONObject();
  48. /*
  49. 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.
  50. 1. Not required
  51. 2. Use default transcode template group id when empty
  52. */
  53. produceConfig.put("TemplateGroupId", null);
  54. return produceConfig.toString();
  55. }

创建云剪辑工程

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

  1. import com.aliyuncs.vod.model.v20170321.AddEditingProjectRequest;
  2. import com.aliyuncs.vod.model.v20170321.AddEditingProjectResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. AddEditingProjectRequest request = new AddEditingProjectRequest();
  9. // Build Editing Project Timeline
  10. request.setTimeline(buildTimeline());
  11. // Set Editing Project Title
  12. request.setTitle("Editing Project Title");
  13. // Set Editing Project Description
  14. request.setDescription("Editing Project Description");
  15. // Set Editing Project Cover URL
  16. request.setCoverURL("http://test.testvod123.com/editingproject/cover/projectid.jpg");
  17. AddEditingProjectResponse response = null;
  18. try {
  19. response = client.getAcsResponse(request);
  20. if (response != null){
  21. if (response.getProject() != null){
  22. System.out.println("Editing Project ID:" + response.getProject().getProjectId());
  23. System.out.println("Editing Project Title:" + response.getProject().getTitle());
  24. System.out.println("Editing Project Create Time:" + response.getProject().getCreationTime());
  25. System.out.println("Editing Project Description:" + response.getProject().getDescription());
  26. System.out.println("Editing Project Status:" + response.getProject().getStatus());
  27. }
  28. // Request ID
  29. System.out.println("RequestId:" + response.getRequestId());
  30. }
  31. } catch (ServerException e){
  32. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  33. } catch (ClientException e){
  34. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  35. } catch (Exception e) {
  36. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  37. }
  38. }
  39. /**
  40. * This Sample shows how to merge two videos
  41. */
  42. public static String buildTimeline(){
  43. JSONObject timeline = new JSONObject();
  44. // Video Track
  45. JSONArray videoTracks = new JSONArray();
  46. JSONObject videoTrack = new JSONObject();
  47. // Video Track Clips
  48. JSONArray videoTrackClips = new JSONArray();
  49. JSONObject videoTrackClip1 = new JSONObject();
  50. videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
  51. videoTrackClips.add(videoTrackClip1);
  52. JSONObject videoTrackClip2 = new JSONObject();
  53. videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
  54. videoTrackClips.add(videoTrackClip2);
  55. videoTrack.put("VideoTrackClips", videoTrackClips);
  56. videoTracks.add(videoTrack);
  57. timeline.put("VideoTracks", videoTracks);
  58. return timeline.toString();
  59. }

修改云剪辑工程

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

  1. import com.aliyuncs.vod.model.v20170321.UpdateEditingProjectRequest;
  2. import com.aliyuncs.vod.model.v20170321.UpdateEditingProjectResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. UpdateEditingProjectRequest request = new UpdateEditingProjectRequest();
  9. request.setProjectId("YourProjectId");
  10. // Set Editing Project Timeline
  11. request.setTimeline(buildTimeline());
  12. // Set Editing Project Title
  13. request.setTitle("Editing Project Title");
  14. // Set Editing Project Description
  15. request.setDescription("Editing Project Description");
  16. // Set Editing Project Cover URL
  17. request.setCoverURL("http://test.testvod123.com/editingproject/cover/projectid.jpg");
  18. UpdateEditingProjectResponse response = null;
  19. try {
  20. response = client.getAcsResponse(request);
  21. if (response != null){
  22. // Request ID
  23. System.out.println("RequestId:" + response.getRequestId());
  24. }
  25. } catch (ServerException e){
  26. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  27. } catch (ClientException e){
  28. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  29. } catch (Exception e) {
  30. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  31. }
  32. }
  33. /**
  34. * This Sample shows how to merge two videos
  35. */
  36. public static String buildTimeline(){
  37. JSONObject timeline = new JSONObject();
  38. // Video Track
  39. JSONArray videoTracks = new JSONArray();
  40. JSONObject videoTrack = new JSONObject();
  41. // Video Track
  42. JSONArray videoTrackClips = new JSONArray();
  43. JSONObject videoTrackClip1 = new JSONObject();
  44. videoTrackClip1.put("MediaId", "11119b4d7cf14dc7b83b0e801cbe1ce6");
  45. videoTrackClips.add(videoTrackClip1);
  46. JSONObject videoTrackClip2 = new JSONObject();
  47. videoTrackClip2.put("MediaId", "22229b4d7cf14dc7b83b0e801cbe1ce6");
  48. videoTrackClips.add(videoTrackClip2);
  49. videoTrack.put("VideoTrackClips", videoTrackClips);
  50. videoTracks.add(videoTrack);
  51. timeline.put("VideoTracks", videoTracks);
  52. return timeline.toString();
  53. }

删除云剪辑工程

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

  1. import com.aliyuncs.vod.model.v20170321.DeleteEditingProjectRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteEditingProjectResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. DeleteEditingProjectRequest request = new DeleteEditingProjectRequest();
  9. // Use comma to split Multi Editing Project IDs
  10. request.setProjectIds("projectid1,projectid2");
  11. DeleteEditingProjectResponse response = null;
  12. try {
  13. response = client.getAcsResponse(request);
  14. if (response != null){
  15. // Request ID
  16. System.out.println("RequestId:" + response.getRequestId());
  17. }
  18. } catch (ServerException e){
  19. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  20. } catch (ClientException e){
  21. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  22. } catch (Exception e) {
  23. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  24. }
  25. }

获取单个云剪辑工程

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

  1. import com.aliyuncs.vod.model.v20170321.GetEditingProjectRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetEditingProjectResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. GetEditingProjectRequest request = new GetEditingProjectRequest();
  9. request.setProjectId("projectId");
  10. GetEditingProjectResponse response = null;
  11. try {
  12. response = client.getAcsResponse(request);
  13. if (response != null){
  14. if (response.getProject() != null){
  15. System.out.println("Editing Project ID:" + response.getProject().getProjectId());
  16. System.out.println("Editing Project Timeline:" + response.getProject().getTimeline());
  17. System.out.println("Editing Project Title:" + response.getProject().getTitle());
  18. System.out.println("Editing Project Description:" + response.getProject().getDescription());
  19. System.out.println("Editing Project Cover URL:" + response.getProject().getCoverURL());
  20. System.out.println("Editing Project Create Time:" + response.getProject().getCreationTime());
  21. System.out.println("Editing Project Last Modified Time:" + response.getProject().getModifiedTime());
  22. System.out.println("Editing Project Status:" + response.getProject().getStatus());
  23. }
  24. // Request ID
  25. System.out.println("RequestId:" + response.getRequestId());
  26. }
  27. } catch (ServerException e){
  28. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  29. } catch (ClientException e){
  30. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  31. } catch (Exception e) {
  32. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  33. }
  34. }

搜索云剪辑工程

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

  1. import com.aliyuncs.vod.model.v20170321.SearchEditingProjectRequest;
  2. import com.aliyuncs.vod.model.v20170321.SearchEditingProjectResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. SearchEditingProjectRequest request = new SearchEditingProjectRequest();
  9. request.setTitle("Title Keywords");
  10. request.setStartTime("2017-01-11T12:00:00Z");
  11. request.setEndTime("2017-01-12T12:00:00Z");
  12. request.setPageSize(10);
  13. request.setPageNo(1);
  14. SearchEditingProjectResponse response = null;
  15. try {
  16. response = client.getAcsResponse(request);
  17. if (response != null){
  18. if (response.getProjectList() != null && response.getProjectList().size() > 0){
  19. System.out.println("Total Size:" + response.getProjectList().size());
  20. for (int i=0; i<response.getProjectList().size(); i++){
  21. System.out.println("No " + i + " Editing Project");
  22. SearchEditingProjectResponse.Project editingProject = response.getProjectList().get(i);
  23. System.out.println("Editing Project ID:" + editingProject.getProjectId());
  24. System.out.println("Editing Project Title:" + editingProject.getTitle());
  25. System.out.println("Editing Project Description:" + editingProject.getDescription());
  26. System.out.println("Editing Project Cover URL:" + editingProject.getCoverURL());
  27. System.out.println("Editing Project Create Time:" + editingProject.getCreationTime());
  28. System.out.println("Editing Project Last Modified Time:" + editingProject.getModifiedTime());
  29. System.out.println("Editing Project Status:" + editingProject.getStatus());
  30. }
  31. }
  32. // Request ID
  33. System.out.println("RequestId:" + response.getRequestId());
  34. }
  35. } catch (ServerException e){
  36. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  37. } catch (ClientException e){
  38. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  39. } catch (Exception e) {
  40. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  41. }
  42. }

设置云剪辑工程素材

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

  1. import com.aliyuncs.vod.model.v20170321.SetEditingProjectMaterialsRequest;
  2. import com.aliyuncs.vod.model.v20170321.SetEditingProjectMaterialsResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<您的AccessKeyId>", "<您的AccessKeySecret>");
  8. SetEditingProjectMaterialsRequest request = new SetEditingProjectMaterialsRequest();
  9. // Editing Project ID
  10. request.setProjectId("projectid");
  11. // Set Editing Project Material IDs, use comma to split
  12. request.setMaterialIds("materialId1,materialId2");
  13. SetEditingProjectMaterialsResponse response = null;
  14. try {
  15. response = client.getAcsResponse(request);
  16. if (response != null){
  17. // Request ID
  18. System.out.println("RequestId:" + response.getRequestId());
  19. }
  20. } catch (ServerException e){
  21. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  22. } catch (ClientException e){
  23. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  24. } catch (Exception e) {
  25. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  26. }
  27. }

获取云剪辑工程素材

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

  1. import com.aliyuncs.vod.model.v20170321.GetEditingProjectMaterialsRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetEditingProjectMaterialsResponse;
  3. /**
  4. * Sample Code
  5. */
  6. public static void main(String[] args) throws Exception {
  7. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  8. GetEditingProjectMaterialsRequest request = new GetEditingProjectMaterialsRequest();
  9. request.setProjectId("projectid");
  10. request.setType("video");
  11. GetEditingProjectMaterialsResponse response = null;
  12. try {
  13. response = client.getAcsResponse(request);
  14. if (response != null){
  15. if (response.getMaterialList() != null && response.getMaterialList().size() > 0){
  16. for (int i=0; i<response.getMaterialList().size(); i++){
  17. System.out.println("No " + i + " Material");
  18. GetEditingProjectMaterialsResponse.Material material = response.getMaterialList().get(i);
  19. System.out.println("Editing Project Material ID:" + material.getMaterialId());
  20. System.out.println("Editing Project Material Title:" + material.getTitle());
  21. System.out.println("Editing Project Material Category ID:" + material.getCateId());
  22. System.out.println("Editing Project Material Category Name:" + material.getCateName());
  23. System.out.println("Editing Project Material Tags:" + material.getTags());
  24. System.out.println("Editing Project Material Cover URL:" + material.getCoverURL());
  25. System.out.println("Editing Project Material Create Time:" + material.getCreationTime());
  26. System.out.println("Editing Project Material Last Modified Time:" + material.getModifiedTime());
  27. }
  28. }
  29. // Request ID
  30. System.out.println("RequestId:" + response.getRequestId());
  31. }
  32. } catch (ServerException e){
  33. System.out.println("ServerError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  34. } catch (ClientException e){
  35. System.out.println("ClientError code:" + e.getErrCode() + ", message:" + e.getErrMsg());
  36. } catch (Exception e) {
  37. System.out.println("ErrorMessage:" + e.getLocalizedMessage());
  38. }
  39. }