Edit videos, images and audio using PHP and add editing into your applications or workflows using the Shotstack PHP video editing library.
Over 20,000 Businesses & Developers from 119 Countries Trust Shotstack
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 using PHP.
composer require shotstack/shotstack-sdk-php
Require the library and use the classes you need.
require_once(__DIR__ . '/vendor/autoload.php');
use Shotstack\Client\Api\EditApi;
use Shotstack\Client\Configuration;
use Shotstack\Client\Model\Edit;
Set the base URL and API key for your environment.
$config = Configuration::getDefaultConfiguration()
->setHost('https://api.shotstack.io/stage')
->setApiKey('x-api-key', 'YOUR_API_KEY');
Create a video asset and set its properties including source URL and trim points.
$videoAsset = new VideoAsset();
$videoAsset
->setSrc('https://shotstack-assets.s3.amazonaws.com/footage/skater.mp4')
->setTrim(3);
Create the complete edit structure with clips, tracks, timeline and output settings.
$clip = new Clip();
$clip
->setAsset($videoAsset)
->setStart(0)
->setLength(8);
$track = new Track();
$track->setClips([$clip]);
$timeline = new Timeline();
$timeline->setTracks([$track]);
$output = new Output();
$output
->setFormat('mp4')
->setResolution('sd');
$edit = new Edit();
$edit
->setTimeline($timeline)
->setOutput($output);
Send the edit to the API for rendering.
$editApi = new EditApi(null, $config);
try {
$response = $editApi->postRender($edit);
$renderId = $response->getResponse()->getId();
echo "Render ID: " . $renderId . "
";
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), "
";
}
The PHP code above creates a JSON payload that describes the video editing parameters, sends it to the Shotstack API, and generates a trimmed video.
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!
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.
Shotstack was EXACTLY what I was looking for, and incredibly easy to get started with. You guys are killing it.
Unlimited developer sandbox
No credit card required