This topic provides examples on how to use the API operations of the video editing module. The API operations are encapsulated in ApsaraVideo VOD SDK for Python. You can call the API operations to create, modify, and delete online editing projects. You can also query details of an online editing project, set materials for an online editing project, and submit a video production job.
Usage notes
In this example, an AccessKey pair is used to initialize a client instance.
For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentation in the top navigation bar to view information related to the API operation.
This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.
Initialize a client
Before you use the SDK, initialize a client. For more information, see Initialization.
Submit a video production job based on a timeline
You can call the ProduceEditingProjectVideo operation to submit a video production job based on a timeline.
In most cases, a timeline is used to produce videos.
Click ProduceEditingProjectVideo to learn more about this API operation.
Sample code:
For more examples on how to produce videos based on timelines, see the "Examples" section of the Overview topic.
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 example: 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
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())
Submit a video production job based on an online editing project
You can call the ProduceEditingProjectVideo operation to submit a video production job based on an online editing project.
If you have high management requirements for online editing projects, use this method for video production.
Click ProduceEditingProjectVideo to learn more about this API operation.
Sample code:
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())
Create an online editing project
You can call the AddEditingProject operation to create an online editing project.
Click AddEditingProjectVideo to learn more about this API operation.
Sample code:
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())
Modify an online editing project
You can call the UpdateEditingProject operation to modify an online editing project.
Click UpdateEditingProjectVideo to learn more about this API operation.
Sample code:
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())
Delete an online editing project
You can call the DeleteEditingProject operation to delete an online editing project.
Click DeleteEditingProjectVideo to learn more about this API operation.
Query details of an online editing project
You can call the GetEditingProject operation to query details about an online editing project.
Click GetEditingProjectVideo to learn more about this API operation.
Query online editing projects
You can call the SearchEditingProject operation to search for online editing projects.
Click SearchEditingProjectVideo to learn more about this API operation.
Set materials for an online editing project
You can call the SetEditingProjectMaterials operation to set materials for an online editing project.
Click SetEditingProjectMaterials to learn more about this API operation.
Query materials in an online editing project
You can call the GetEditingProjectMaterials operation to query the materials in an online editing project.
Click GetEditingProjectMaterials to learn more about this API operation.