How to Merge Videos using an API?

When creating or editing videos, you sometimes need to join multiple video clips together. Think of a scenario where you have several video fragments that you want to stitch into a single video. For example, you may want to add an intro or outro to a video recording. You can merge video programmatically using a video editing API. Here's how with a single API request:

API Request
curl -s -X POST https://api.creatomate.com/v1/renders \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-binary @- << EOF
{
  "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"
          }
        ]
      }
    ]
  }
}
EOF
Output Video

How it works: This example shows how to use cURL to invoke the REST API for concatenating two videos. However, you can use any other tool or programming language to perform this API request. Thanks to JSON's flexibility, we can generate any kind of video by just specifying how the video should be edited programmatically. The API takes care of the rest.

In order to merge two videos, we create a very basic video composition in which we specify each video element that we want to merge. Just like in a visual video editor, the videos will play one after the other when they're placed on the same video track (track "1" in this example).

To add a smooth transition between the two video clips, you can use the "animations" property, through which you can apply various effects. In this example, we apply a 1-second fade animation to the second video element. When the "transition" property is set to "true", it overlaps with the first video clip. In addition to the fade animation, there are many other effects that can be used to combine multiple videos.

Creatomate's video editing API offers a wide range of video editing capabilities, including merging videos. With the REST API, based on JSON, any video editing task can be automated. Combined with the online video editor, it provides you with all the tools you need to quickly set up code-driven video editing workflows. Check out the editor below and create a video design based on your editing needs.

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 application to create any kind of video – completely through code.

Related API Video Editing Questions

Start automating today

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