All Products
Search
Document Center

Video editing

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see init_vod_client.

Produce videos based on a timeline

In most scenarios, you can use this method to produce videos. For more information about the request and response parameters, see ProduceEditingProjectVideo.

For more information about examples of producing videos based on a timeline, see Video editing: Examples.

from aliyunsdkvod.request.v20170321 import ProduceEditingProjectVideoRequest
def produce_editing_video(clt):
    request = ProduceEditingProjectVideoRequest.ProduceEditingProjectVideoRequest()

    # Constructs a timeline for producing videos. The following example 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))

    # Specifies the metadata of the produced video.
    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))

    # Specifies the production configuration.
    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())

Produce videos based on an online editing project

If online editing projects need to be managed with high requirements, you can use this method to produce videos. For more information about the request and response parameters, see ProduceEditingProjectVideo.

from aliyunsdkvod.request.v20170321 import ProduceEditingProjectVideoRequest
def produce_editing_video_by_id(clt):
    request = ProduceEditingProjectVideoRequest.ProduceEditingProjectVideoRequest()

    # Sets the ID of the online editing project.
    request.set_ProjectId('<ProjectId>')

    # Specifies the metadata of the produced video.
    mediaMetadata = {'Title': 'editing sample title by ProjectId', 'Description': 'editing sample description by ProjectId',
                     'Tags': 'Tag1,Tag2,Test'}
    request.set_MediaMetadata(json.dumps(mediaMetadata))

    # Specifies the production configuration.
    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())

Create an online editing project

For more information about the request and response parameters, see AddEditingProject.

from aliyunsdkvod.request.v20170321 import AddEditingProjectRequest
def add_editing_project(clt):
    request = AddEditingProjectRequest.AddEditingProjectRequest()

    # Constructs a timeline of the online editing project. The following example 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))

    # Specifies the metadata of the online editing project.
    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())

Modify an online editing project

For more information about the request and response parameters, see UpdateEditingProject.

from aliyunsdkvod.request.v20170321 import UpdateEditingProjectRequest
def update_editing_project(clt):
    request = UpdateEditingProjectRequest.UpdateEditingProjectRequest()

    # Sets the ID of the online editing project.
    request.set_ProjectId('<projectId>')

    # Constructs a timeline of the online editing project. The following example 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))

    # Specifies the metadata of the online editing project.
    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())

Delete one or more online editing projects

For more information about the request and response parameters, see DeleteEditingProject.

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

    # Specifies the IDs of the online editing projects to be deleted.
    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())

Obtain the information about an online editing project

For more information about the request and response parameters, see GetEditingProject.

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

    # Sets the ID of the online editing project.
    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())

Search for online editing projects

For more information about the request and response parameters, see 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())

Set materials to be edited for an online editing project

For more information about the request and response parameters, see 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())

Obtain a list of materials to be edited for an online editing project

For more information about the request and response parameters, see 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())