How to Merge Videos using PHP?

Sometimes, you might come across situations where you need to join multiple videos together. Imagine a scenario where you have various video clips that you want to stitch into one seamless video. For instance, let's say you want to attach an outro to a recorded video. To make this happen using PHP, you'll require a video editing API. Here's a quick and easy way to achieve this in your own PHP application using just a few lines of code:

Input Code
// Don't forget to install the required library using Composer:
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');

$output = $client->render([
 'source' => new Creatomate\Source([
  'output_format' => 'mp4',
  'width' => 1920,
  'height' => 1080,
  'elements' => [
    'type' => 'video',
    'track' => 1,
    'source' => ''
    'type' => 'video',
    'track' => 1,
    'source' => '',
    'animations' => [
      'time' => 'start',
      'duration' => 1,
      'transition' => true,
      'type' => 'fade'

Output Video

How it works: Start by installing the Creatomate library from Packagist using Composer. To play the video clips in sequence, each element must be placed on the same track (in this case, track 1). No need to specify the start and duration for each clip, as the track adjusts automatically based on the total footage. To combine two videos, simply provide the URLs where they're hosted, and let the API handle the rest.

For a smooth transition between clips, use the "animations" property. This property accepts an array of animations applied to the element. In this case, we add a 1-second fade animation to the second video element. By setting the "transition" property to "true", it overlaps with the first video clip. The output video above shows the result after rendering. The fade animation is just one of many effects that can be applied to merging together multiple videos.

Merging videos is one of the features offered by the Creatomate video editing API. The JSON-based API allows automating any kind of video editing task in PHP. Together with the online video editor, it gives you all the tools you need to quickly set up code-driven video editing. Check out the editor below to see how to create your own video scenarios in PHP.

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

Related PHP Video Editing Questions

Start automating today

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