本篇文档提供了Python SDK视频剪辑模块相关功能的API调用示例。包含发起剪辑合成、创建云剪辑工程、修改云剪辑工程、删除云剪辑工程、获取单个云剪辑工程、设置云剪辑工程素材等。

接口调用说明

  • 本文提供的接口调用示例均通过AccessKey初始化客户端实例。

  • 接口的参数解释和返回字段的详细说明请访问 阿里云OpenAPI门户 ,在各接口右侧的 文档 页签查看。

  • 本文仅提供部分复杂接口的代码示例,其余接口的SDK代码示例,可以通过阿里云OpenAPI门户获取。访问 阿里云OpenAPI门户 ,在接口的左侧 参数配置 页签,填写需要的参数信息并发起调用后,在右侧的 SDK示例 页签,选择SDK版本,选择目标语言,查看并下载示例代码。

  • 本文均以V1.0版本的SDK为例进行接口调用,如需获取V2.0版本的SDK示例,请在通过阿里云OpenAPI门户获取SDK示例时,指定到对应的SDK版本。 image.png

初始化客户端

使用前请先初始化客户端,请参见 初始化

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

调用ProduceEditingProjectVideo接口,生成通过时间线-发起剪辑合成的示例。

绝大多数场景下,使用这种方式即可合成视频。

阿里云OpenAPI门户地址: ProduceEditingProjectVideo

调用示例如下:

说明

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

from aliyunsdkvod.request.v20170321 import ProduceEditingProjectVideoRequest
def produce_editing_video(clt):
    request = ProduceEditingProjectVideoRequest.ProduceEditingProjectVideoRequest()
    # set timeline, this sample shows how to merge two videos
    videoTrackClips = []
    videoTracks = []
    timeline = {}
    videoTrackClip1 = {'MediaId': '<videoId1>'}
    videoTrackClips.append(videoTrackClip1)
    videoTrackClip2 = {'MediaId': '<videoId2>'}
    videoTrackClips.append(videoTrackClip2)
    videoTrack = {'VideoTrackClips': videoTrackClips}
    videoTracks.append(videoTrack)
    timeline['VideoTracks'] = videoTracks
    request.set_Timeline(json.dumps(timeline))
    # set media metadata
    # CoverURL示例:http://example.aliyundoc.com/media/cover/mediaid****.jpg
    mediaMetadata = {'Title': 'editing sample title', 'Description': 'editing sample description', 'Tags': 'Tag1,Tag2,Test',
                     'CoverURL': '<your Cover URL>'}
    request.set_MediaMetadata(json.dumps(mediaMetadata))
    # set produce config
    produceConfig = {'TemplateGroupId': '<templateGroupId>'}
    #request.set_ProduceConfig(json.dumps(produceConfig))
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    produce = produce_editing_video(clt)
    print(produce['MediaId'])
    print(json.dumps(produce, ensure_ascii=False, indent=4))
except Exception as e:
    print(e)
    print(traceback.format_exc())

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

调用ProduceEditingProjectVideo接口,通过云剪辑工程-发起剪辑合成的示例。

对云剪辑工程有较高管理需求的场景下,可以使用这种方式合成视频。

阿里云OpenAPI门户地址: ProduceEditingProjectVideo

调用示例如下:

from aliyunsdkvod.request.v20170321 import ProduceEditingProjectVideoRequest
def produce_editing_video_by_id(clt):
    request = ProduceEditingProjectVideoRequest.ProduceEditingProjectVideoRequest()
    # set ProjectId
    request.set_ProjectId('<ProjectId>')
    # set media metadata
    mediaMetadata = {'Title': 'editing sample title by ProjectId', 'Description': 'editing sample description by ProjectId',
                     'Tags': 'Tag1,Tag2,Test'}
    request.set_MediaMetadata(json.dumps(mediaMetadata))
    # set produce config
    produceConfig = {'TemplateGroupId': '<templateGroupId>'}
    #request.set_ProduceConfig(json.dumps(produceConfig))
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    produce = produce_editing_video_by_id(clt)
    print(produce['MediaId'])
    print(json.dumps(produce, ensure_ascii=False, indent=4))
except Exception as e:
    print(e)
    print(traceback.format_exc())

创建云剪辑工程

调用AddEditingProject接口,完成创建云剪辑工程功能。

阿里云OpenAPI门户地址: AddEditingProject

调用示例如下:

from aliyunsdkvod.request.v20170321 import AddEditingProjectRequest
def add_editing_project(clt):
    request = AddEditingProjectRequest.AddEditingProjectRequest()
    # set timeline, this sample shows how to merge two videos
    videoTrackClips = []
    videoTracks = []
    timeline = {}
    videoTrackClip1 = {'MediaId': '<videoId1>'}
    videoTrackClips.append(videoTrackClip1)
    videoTrackClip2 = {'MediaId': '<videoId2>'}
    videoTrackClips.append(videoTrackClip2)
    videoTrack = {'VideoTrackClips': videoTrackClips}
    videoTracks.append(videoTrack)
    timeline['VideoTracks'] = videoTracks
    request.set_Timeline(json.dumps(timeline))
    # set project metadata
    request.set_Title('editing project title')
    request.set_Description('editing project description')
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    project = add_editing_project(clt)
    print(project['Project'])
    print(json.dumps(project, ensure_ascii=False, indent=4))
except Exception as e:
    print(e)
    print(traceback.format_exc())

修改云剪辑工程

调用UpdateEditingProject接口,完成修改云剪辑工程功能。

阿里云OpenAPI门户地址: UpdateEditingProject

调用示例如下:

from aliyunsdkvod.request.v20170321 import UpdateEditingProjectRequest
def update_editing_project(clt):
    request = UpdateEditingProjectRequest.UpdateEditingProjectRequest()
    # set projectId
    request.set_ProjectId('<projectId>')
    # set timeline, this sample shows how to merge two videos
    videoTrackClips = []
    videoTracks = []
    timeline = {}
    videoTrackClip1 = {'MediaId': '<videoId1>'}
    videoTrackClips.append(videoTrackClip1)
    videoTrackClip2 = {'MediaId': '<videoId2>'}
    videoTrackClips.append(videoTrackClip2)
    videoTrack = {'VideoTrackClips': videoTrackClips}
    videoTracks.append(videoTrack)
    timeline['VideoTracks'] = videoTracks
    request.set_Timeline(json.dumps(timeline))
    # set project metadata
    request.set_Title('new editing project title')
    request.set_Description('new editing project description')
    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = update_editing_project(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))
except Exception as e:
    print(e)
    print(traceback.format_exc())

删除云剪辑工程

调用DeleteEditingProject接口,完成删除云剪辑工程功能。

阿里云OpenAPI门户地址: DeleteEditingProject

获取单个云剪辑工程

调用GetEditingProject接口,完成获取单个云剪辑工程功能。

阿里云OpenAPI门户地址: GetEditingProject

搜索云剪辑工程

调用SearchEditingProject接口,完成搜索云剪辑工程功能。

阿里云OpenAPI门户地址: SearchEditingProject

设置云剪辑工程素材

调用SetEditingProjectMaterials接口,完成设置云剪辑工程素材功能。

阿里云OpenAPI门户地址: SetEditingProjectMaterials

获取云剪辑工程素材

调用GetEditingProjectMaterials接口,完成获取云剪辑工程素材功能。

阿里云OpenAPI门户地址: GetEditingProjectMaterials