全部产品
云市场

视频剪辑

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

初始化客户端

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

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

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

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

  1. from aliyunsdkvod.request.v20170321 import ProduceEditingProjectVideoRequest
  2. def produce_editing_video(clt):
  3. request = ProduceEditingProjectVideoRequest.ProduceEditingProjectVideoRequest()
  4. # set timeline, this sample shows how to merge two videos
  5. videoTrackClips = []
  6. videoTracks = []
  7. timeline = {}
  8. videoTrackClip1 = {'MediaId': '<videoId1>'}
  9. videoTrackClips.append(videoTrackClip1)
  10. videoTrackClip2 = {'MediaId': '<videoId2>'}
  11. videoTrackClips.append(videoTrackClip2)
  12. videoTrack = {'VideoTrackClips': videoTrackClips}
  13. videoTracks.append(videoTrack)
  14. timeline['VideoTracks'] = videoTracks
  15. request.set_Timeline(json.dumps(timeline))
  16. # set media metadata
  17. mediaMetadata = {'Title': 'editing sample title', 'Description': 'editing sample description', 'Tags': 'Tag1,Tag2,Test',
  18. 'CoverURL': 'http://test.testvod123.com/media/cover/mediaid.jpg'}
  19. request.set_MediaMetadata(json.dumps(mediaMetadata))
  20. # set produce config
  21. produceConfig = {'TemplateGroupId': '<templateGroupId>'}
  22. #request.set_ProduceConfig(json.dumps(produceConfig))
  23. request.set_accept_format('JSON')
  24. response = json.loads(clt.do_action_with_exception(request))
  25. return response
  26. try:
  27. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  28. produce = produce_editing_video(clt)
  29. print(produce['MediaId'])
  30. print(json.dumps(produce, ensure_ascii=False, indent=4))
  31. except Exception as e:
  32. print(e)
  33. print(traceback.format_exc())

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

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

  1. from aliyunsdkvod.request.v20170321 import ProduceEditingProjectVideoRequest
  2. def produce_editing_video_by_id(clt):
  3. request = ProduceEditingProjectVideoRequest.ProduceEditingProjectVideoRequest()
  4. # set ProjectId
  5. request.set_ProjectId('<ProjectId>')
  6. # set media metadata
  7. mediaMetadata = {'Title': 'editing sample title by ProjectId', 'Description': 'editing sample description by ProjectId',
  8. 'Tags': 'Tag1,Tag2,Test'}
  9. request.set_MediaMetadata(json.dumps(mediaMetadata))
  10. # set produce config
  11. produceConfig = {'TemplateGroupId': '<templateGroupId>'}
  12. #request.set_ProduceConfig(json.dumps(produceConfig))
  13. request.set_accept_format('JSON')
  14. response = json.loads(clt.do_action_with_exception(request))
  15. return response
  16. try:
  17. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  18. produce = produce_editing_video_by_id(clt)
  19. print(produce['MediaId'])
  20. print(json.dumps(produce, ensure_ascii=False, indent=4))
  21. except Exception as e:
  22. print(e)
  23. print(traceback.format_exc())

创建云剪辑工程

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

  1. from aliyunsdkvod.request.v20170321 import AddEditingProjectRequest
  2. def add_editing_project(clt):
  3. request = AddEditingProjectRequest.AddEditingProjectRequest()
  4. # set timeline, this sample shows how to merge two videos
  5. videoTrackClips = []
  6. videoTracks = []
  7. timeline = {}
  8. videoTrackClip1 = {'MediaId': '<videoId1>'}
  9. videoTrackClips.append(videoTrackClip1)
  10. videoTrackClip2 = {'MediaId': '<videoId2>'}
  11. videoTrackClips.append(videoTrackClip2)
  12. videoTrack = {'VideoTrackClips': videoTrackClips}
  13. videoTracks.append(videoTrack)
  14. timeline['VideoTracks'] = videoTracks
  15. request.set_Timeline(json.dumps(timeline))
  16. # set project metadata
  17. request.set_Title('editing project title')
  18. request.set_Description('editing project description')
  19. request.set_accept_format('JSON')
  20. response = json.loads(clt.do_action_with_exception(request))
  21. return response
  22. try:
  23. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  24. project = add_editing_project(clt)
  25. print(project['Project'])
  26. print(json.dumps(project, ensure_ascii=False, indent=4))
  27. except Exception as e:
  28. print(e)
  29. print(traceback.format_exc())

修改云剪辑工程

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

  1. from aliyunsdkvod.request.v20170321 import UpdateEditingProjectRequest
  2. def update_editing_project(clt):
  3. request = UpdateEditingProjectRequest.UpdateEditingProjectRequest()
  4. # set projectId
  5. request.set_ProjectId('<projectId>')
  6. # set timeline, this sample shows how to merge two videos
  7. videoTrackClips = []
  8. videoTracks = []
  9. timeline = {}
  10. videoTrackClip1 = {'MediaId': '<videoId1>'}
  11. videoTrackClips.append(videoTrackClip1)
  12. videoTrackClip2 = {'MediaId': '<videoId2>'}
  13. videoTrackClips.append(videoTrackClip2)
  14. videoTrack = {'VideoTrackClips': videoTrackClips}
  15. videoTracks.append(videoTrack)
  16. timeline['VideoTracks'] = videoTracks
  17. request.set_Timeline(json.dumps(timeline))
  18. # set project metadata
  19. request.set_Title('new editing project title')
  20. request.set_Description('new editing project description')
  21. request.set_accept_format('JSON')
  22. response = json.loads(clt.do_action_with_exception(request))
  23. return response
  24. try:
  25. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  26. res = update_editing_project(clt)
  27. print(json.dumps(res, ensure_ascii=False, indent=4))
  28. except Exception as e:
  29. print(e)
  30. print(traceback.format_exc())

删除云剪辑工程

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

  1. from aliyunsdkvod.request.v20170321 import DeleteEditingProjectRequest
  2. def delete_editing_project(clt):
  3. request = DeleteEditingProjectRequest.DeleteEditingProjectRequest()
  4. # set projectId list
  5. request.set_ProjectIds('projectId1,projectId2')
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. res = delete_editing_project(clt)
  12. print(json.dumps(res, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

获取单个云剪辑工程

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

  1. from aliyunsdkvod.request.v20170321 import GetEditingProjectRequest
  2. def get_editing_project(clt):
  3. request = GetEditingProjectRequest.GetEditingProjectRequest()
  4. # set projectId
  5. request.set_ProjectId('<ProjectId>')
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. project = get_editing_project(clt)
  12. print(json.dumps(project, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

搜索云剪辑工程

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

  1. from aliyunsdkvod.request.v20170321 import SearchEditingProjectRequest
  2. def search_editing_project(clt):
  3. request = SearchEditingProjectRequest.SearchEditingProjectRequest()
  4. request.set_Title('Title Keywords')
  5. request.set_StartTime('2018-10-11T12:00:00Z')
  6. request.set_EndTime('2018-12-25T12:00:00Z')
  7. request.set_PageSize(10)
  8. request.set_PageNo(1)
  9. request.set_accept_format('JSON')
  10. response = json.loads(clt.do_action_with_exception(request))
  11. return response
  12. try:
  13. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  14. projects = search_editing_project(clt)
  15. print(projects['ProjectList']['Project'])
  16. print(json.dumps(projects, ensure_ascii=False, indent=4))
  17. except Exception as e:
  18. print(e)
  19. print(traceback.format_exc())

设置云剪辑工程素材

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

  1. from aliyunsdkvod.request.v20170321 import SetEditingProjectMaterialsRequest
  2. def set_editing_project_materials(clt):
  3. request = SetEditingProjectMaterialsRequest.SetEditingProjectMaterialsRequest()
  4. request.set_ProjectId('<ProjectId>')
  5. request.set_MaterialIds('materialId1,materialId2')
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. res = set_editing_project_materials(clt)
  12. print(json.dumps(res, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

获取云剪辑工程素材

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

  1. from aliyunsdkvod.request.v20170321 import GetEditingProjectMaterialsRequest
  2. def get_editing_project_materials(clt):
  3. request = GetEditingProjectMaterialsRequest.GetEditingProjectMaterialsRequest()
  4. request.set_ProjectId('<ProjectId>')
  5. request.set_Type('video')
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. res = get_editing_project_materials(clt)
  12. print(json.dumps(res, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())