How to Create Split Screen Videos using Python?

Split screen is a method of displaying multiple videos side-by-side by dividing the screen into two sections, either vertically or horizontally. To create a splitscreen video in Python, you'll need a video editing API capable of processing video files. Here is how to accomplish that in Python code with just a few lines:

Input Code
import requests

json = {
 'source': {
  'output_format': 'mp4',
  'width': 1920,
  'height': 1080,
  'duration': 6,
  'elements': [
    'type': 'video',
    'source': '',
    'x': '25%',
    'width': '50%'
    'type': 'video',
    'source': '',
    'x': '75%',
    'width': '50%'

response =
  # Find your API key under 'Project Settings' in your account:
  'Authorization': 'Bearer Your-API-Key',
  'Content-Type': 'application/json',

# Wait a minute, then visit the URL provided in the response:

Output Video

How it works: The REST API can be accessed through Python's standard "requests" package, without the need to install any additional software. The output video is based on a composition we define in our Python code. Here's how it works.

First off, decide on the resolution you want for your final video. For our example, let's go with a landscape layout of 1080p (1920 by 1080) using two input videos.

To display both videos side-by-side, we'll make use of the "x" and "width" properties. These positions are based on the center of each video element. To position them on the left and right sides, set the positions to "25%" and "75%" respectively. To ensure equal horizontal distribution, set the width of each element to "50%".

We're only changing the horizontal properties ("x" and "width") and leaving the vertical properties ("y" and "height") as they are. By default, the "y" position and height of an element are set to "50%" and "100%" respectively, filling up the entire vertical space. Therefore, we do not need to specify these values for this example. However, if we wanted to offset the videos vertically, we could do so as well.

If you want to play around with different values, you can try using a video editor that allows building a video composition by dragging and dropping. Once you're satisfied with your video template, the editor will automatically generate the necessary Python code.

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