Build Video Applications with PHP

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.

Getting Started

Installation

The Shotstack PHP video editing library is available via Composer/Packagist or downloaded directly from GitHub.

composer require shotstack/shotstack-sdk-php

Usage

1. Require the library

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;
2. Configure the API client

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');
3. Create a video asset

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);
4. Create and configure the edit

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);
5. Submit the edit

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(), "
";
}

Output

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.

EXPLORE

Check our PHP video editing examples and demos on GitHub

DISCOVER

See what the Shotstack API and PHP can do

More to do