There are times when you need to programmatically stitch multiple videos. Perhaps you are developing a Python application where you would like to automatically join several video clips into a single video, such as adding an outro to a video recording. To accomplish this using Python, you will need an editing API to perform the video processing. Here's a simple and straightforward method to merge videos with just a few lines of code:
import requests
json = {
'source': {
'output_format': 'mp4',
'width': 1920,
'height': 1080,
'elements': [
{
'type': 'video',
'track': 1,
'source': 'https://cdn.creatomate.com/demo/drone.mp4'
},
{
'type': 'video',
'track': 1,
'source': 'https://cdn.creatomate.com/demo/river.mp4',
'animations': [
{
'time': 'start',
'duration': 1,
'transition': True,
'type': 'fade'
}
]
}
]
}
}
response = requests.post(
'https://api.creatomate.com/v1/renders',
headers={
# Find your API key under 'Project Settings' in your account:
# https://creatomate.com/docs/api/rest-api/authentication
'Authorization': 'Bearer Your-API-Key',
'Content-Type': 'application/json',
},
json=json
)
# Wait a minute, then visit the URL provided in the response:
print(response.json())
How it works: As the API runs entirely in the cloud, there is no need to install any Python dependencies. The only package that is required is the standard "requests" package included with your Python installation.
For the video to play sequentially, we create a video composition with two video elements on the same track (track "1"). There is no need to specify the start and duration of each clip as the track adjusts automatically according to the total footage. Simply provide the URLs of the videos and the API takes care of everything else.
For a seamless transition between clips, use the "animations" property. This property accepts an array of animations to be applied to the element. In this case, we apply a 1-second fade animation to the second video element. By setting the "transition" property to "true", it smoothly overlaps with the first video clip. The fade animation is just one of many effects that can be used to combine multiple videos.
Creatomate's video editing API offers a wide range of video editing capabilities, including the ability to merge videos. With this REST API, based on JSON, you can automate any sort of editing task. As it comes with an online video editor, it provides developers with all the necessary tools to efficiently set up code-driven video editing workflows. See how you can create your own video scenarios ready for use in your Python applications below.