PHP Video Editor

Edit videos, images and audio using PHP and add editing into your applications or workflows using the Shotstack PHP video editing library.

Editing video using PHP

LOVED BY DEVELOPERS

Used every day by developers at businesses large and small

Twitter
McDonalds
Winny
Aryeo
Sparcstart Amplify
Smartkarma

Easy to learn and get started, the Shotstack PHP SDK will help you and your developers build a video editing application in days instead of months.

The open-source PHP video editing library talks directly to Shotstack's fully managed video editing API which means you don't need to worry about setting up servers, installing FFmpeg or creating your own PHP video editing scripts.

The PHP video editing SDK provides access to all of Shotstack's video editing features including cut and trim, stitching clips, transitions, filters and effects and lets you merge videos, images, text and audio.

Installation

The Shotstack PHP video editing library is available as a Composer package and can be installed directly from Packagist.

composer require shotstack/shotstack-sdk-php

Usage

1. Require the library

Require the library in to your script. Make sure the path is correct and points to the vendor folder at the root of your project.

require 'vendor/autoload.php';
2. Import features

Import the features from the SDK needed to create a basic edit using use statements.

use Shotstack\Client\Api\EditApi;
use Shotstack\Client\Configuration;
use Shotstack\Client\Model\Edit;
use Shotstack\Client\Model\Output;
use Shotstack\Client\Model\Timeline;
use Shotstack\Client\Model\Track;
use Shotstack\Client\Model\Clip;
use Shotstack\Client\Model\VideoAsset;
3. Authenticate

Authenticate and configure the client library. Register and replace the key with your own API key and set the host to stage or v1. Ideally you will load the key using environment variables.

$config = Configuration::getDefaultConfiguration()
->setHost('https://api.shotstack.io/stage')
->setApiKey('x-api-key', 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD');

$client = new EditApi(null, $config);
4. Trim a video clip

The possibilities are limitless but in this example a video clips start and end point will be trimmed. Set the video asset trim to 3 to chop the first 3 seconds off the clip and then play the next 8 seconds by setting the length to 8. Setting the start to 0 means the video clip start straight away.

$videoAsset = new VideoAsset();
$videoAsset
->setSrc('https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4')
->setTrim(3);

$videoClip = new Clip();
$videoClip
->setAsset($videoAsset)
->setLength(8)
->setStart(0);
5. Add the clip to a track

Each clip needs to be added to an array of a track. You can have multiple tracks layered over the top of each other.

$track = new Track();
$track->setClips([$videoClip]);
6. Add the track to the timeline

The timeline is made up of tracks that specifies the sequence of clips and when they start and finish.

$timeline = new Timeline();
$timeline->setTracks([$track]);
7. Set the video output specification

To create a video the output format and resolution need to be specified, in this example an SD resolution is used and output is mp4.

$output = new Output();
$output
->setFormat('mp4')
->setResolution('sd');
8. Create the video edit

The final edit is made up of the timeline and the output format.

$edit = new Edit();
$edit
->setTimeline($timeline)
->setOutput($output);
9. POST the edit to the API

Post the edit to the API for rendering.

$render = $client->postRender($edit)->getResponse();
10. Get the rendered video URL

Finally, check the status of the render, and when done output the video URL.

$video = $client->getRender($render->getId())->getResponse();

if ($video->getStatus() === 'done') {
echo $video->getUrl();
}

Output

The PHP code above will prepare a JSON payload, describing the video editing parameters to trim a video clip, POST it to the Shotstack API and generate this video.

EXPLORE

Get started with our PHP video editing examples on GitHub

DISCOVER

See what the Shotstack API and PHP can do

This application is the perfect example of a well executed and documented API. In less than 10 mins, set up, web hook done, and first render! Mike Maberry, Gunslinger.dev
There are a couple of other options out there that attempt to provide the same or similar solution, but none of them come close in terms of quality, ease of use, and speed. Adam Chubbuck, Software Engineer
Shotstack was EXACTLY what I was looking for, and incredibly easy to get started with. You guys are killing it. Colin Plamondon, thebeam.fm

Experience Shotstack for yourself, with no risk, and generate your first video in 15 minutes.