全部产品

视频剪辑

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

初始化客户端

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

通过时间线-发起剪辑合

调用ProduceEditingProjectVideo接口,完成通过时间线-发起剪辑合功能。

绝大多数场景下,使用这种方式即可合成视频。接口参数和返回字段请参见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
    mediaMetadata = {'Title': 'editing sample title', 'Description': 'editing sample description', 'Tags': 'Tag1,Tag2,Test',
                     'CoverURL': 'http://test.testvod123.com/media/cover/mediaid.jpg'}
    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

try:
    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接口,完成通过云剪辑工程-发起剪辑合成功能。

对云剪辑工程有较高管理需求的场景下,可以使用这种方式合成视频。接口参数和返回字段请参见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

try:
    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接口,完成创建云剪辑工程功能。

接口参数和返回字段请参见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

try:
    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接口,完成修改云剪辑工程功能。

接口参数和返回字段请参见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

try:
    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接口,完成删除云剪辑工程功能。

接口参数和返回字段请参见DeleteEditingProject。调用示例如下:

from aliyunsdkvod.request.v20170321 import DeleteEditingProjectRequest
def delete_editing_project(clt):
    request = DeleteEditingProjectRequest.DeleteEditingProjectRequest()

    # set projectId list
    request.set_ProjectIds('projectId1,projectId2')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = delete_editing_project(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

获取单个云剪辑工程

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

接口参数和返回字段请参见GetEditingProject。调用示例如下:

from aliyunsdkvod.request.v20170321 import GetEditingProjectRequest
def get_editing_project(clt):
    request = GetEditingProjectRequest.GetEditingProjectRequest()

    # set projectId
    request.set_ProjectId('<ProjectId>')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    project = get_editing_project(clt)
    print(json.dumps(project, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

搜索云剪辑工程

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

接口参数和返回字段请参见SearchEditingProject。调用示例如下:

from aliyunsdkvod.request.v20170321 import SearchEditingProjectRequest
def search_editing_project(clt):
    request = SearchEditingProjectRequest.SearchEditingProjectRequest()

    request.set_Title('Title Keywords')
    request.set_StartTime('2018-10-11T12:00:00Z')
    request.set_EndTime('2018-12-25T12:00:00Z')
    request.set_PageSize(10)
    request.set_PageNo(1)

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    projects = search_editing_project(clt)
    print(projects['ProjectList']['Project'])
    print(json.dumps(projects, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

设置云剪辑工程素材

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

接口参数和返回字段请参见SetEditingProjectMaterials。调用示例如下:

from aliyunsdkvod.request.v20170321 import SetEditingProjectMaterialsRequest
def set_editing_project_materials(clt):
    request = SetEditingProjectMaterialsRequest.SetEditingProjectMaterialsRequest()

    request.set_ProjectId('<ProjectId>')
    request.set_MaterialIds('materialId1,materialId2')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = set_editing_project_materials(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())

获取云剪辑工程素材

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

接口参数和返回字段请参见GetEditingProjectMaterials。调用示例如下:

from aliyunsdkvod.request.v20170321 import GetEditingProjectMaterialsRequest
def get_editing_project_materials(clt):
    request = GetEditingProjectMaterialsRequest.GetEditingProjectMaterialsRequest()

    request.set_ProjectId('<ProjectId>')
    request.set_Type('video')

    request.set_accept_format('JSON')
    response = json.loads(clt.do_action_with_exception(request))
    return response

try:
    clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
    res = get_editing_project_materials(clt)
    print(json.dumps(res, ensure_ascii=False, indent=4))

except Exception as e:
    print(e)
    print(traceback.format_exc())