How to Create a Video from Images using Python?

Python is a great programming language for generating videos from a bunch of images quickly. This is commonly used for creating real estate slideshows, e-commerce product videos, and news videos. The following example shows you how to turn a collection of images into a video using Python:

Input Code
import requests

json = {
 # The ID of the template that you created in the online editor.
 'template_id': '58c1163e-f250-49df-b98d-e8c4aad01a2d',

 # Inserting several images into the video template.
 'modifications': {
  'Image-1': 'https://cdn.creatomate.com/demo/living-room.jpg',
  'Image-2': 'https://cdn.creatomate.com/demo/bathroom.jpg',
  'Image-3': 'https://cdn.creatomate.com/demo/kitchen.jpg'
 }
}

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())

Output Video

How it works: For this example, we'll make a video entirely from code using the Creatomate API. As this is a simple REST API, there is no need to install any dependencies. Just by sending a simple API request, we can create a video based on a compilation of images.

To start, you need a video template. Here, we are using a real estate template that includes several photos and property details. The template concludes with an outro displaying the contact information of the realtor. You can find this specific template in the template library, however if you would like to design your own image-based template, you can do so using the online template editor.

When you've got a video template set up in your account, you can create a compilation video by calling the API, providing the template ID and the image URLs you want in the video. For the sake of simplicity, we're only passing three images (Image-1, Image-2, and Image-3). However, you can replace any element in the template, like video footage, colors, or logos, to create a fully programmatically generated video.

As soon as the API has completed creating the video, you can access it through the URL that is returned. If you want, the video may then be further automated within your Python script, for example by publishing it to social media.

To get started, follow this quick tutorial or check out the API documentation.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your Python application to create any kind of video – completely through code.

Related Python Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free