Shotstack Studio
A JavaScript SDK for browser-based video editing with timeline, canvas preview, and export.
Interactive Examples
Try Shotstack Studio in your preferred framework:
Create a new project
The fastest way to get started is to scaffold a project. This creates a small app with the Studio SDK already set up, including the canvas, timeline, and controls.
npm create video-editor@latest
# or
npx create-video-editor
You'll be asked for a project name and a framework. The CLI then scaffolds the app, installs dependencies, starts the dev server, and opens a live editor in your browser.
npx create-video-editor my-video-editor
To skip the prompts, pass the project directory and framework directly:
npx create-video-editor my-editor --template react --yes
Features
- Template-driven editing with undo/redo command model
- Canvas preview rendering
- Visual timeline with drag, resize, selection, and snapping
- Extensible UI via
UIController button API
- Browser export pipeline via
VideoExporter
Installation
To add the SDK to an existing app, install it directly:
npm install @shotstack/shotstack-studio
yarn add @shotstack/shotstack-studio
Quick Start
import { Edit, Canvas, Controls, Timeline, UIController } from "@shotstack/shotstack-studio";
// 1) Load a template
const response = await fetch("https://shotstack-assets.s3.amazonaws.com/templates/hello-world/hello.json");
const template = await response.json();
// 2) Create core components
const edit = new Edit(template);
const canvas = new Canvas(edit);
const ui = UIController.create(edit, canvas);
// 3) Load canvas and edit
await canvas.load();
await edit.load();
// 4) Register toolbar buttons
ui.registerButton({
id: "text",
icon: `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3H13"/><path d="M8 3V13"/><path d="M5 13H11"/></svg>`,
tooltip: "Add Text"
});
// 5) Handle button clicks
ui.on("button:text", ({ position }) => {
edit.addTrack(0, {
clips: [
{
asset: {
type: "rich-text",
text: "Title",
font: { family: "Work Sans", size: 72, weight: 600, color: "#ffffff", opacity: 1 },
align: { horizontal: "center", vertical: "middle" }
},
start: position,
length: 5,
width: 500,
height: 200
}
]
});
});
// 6) Initialize the Timeline
const timelineContainer = document.querySelector("[data-shotstack-timeline]") as HTMLElement;
const timeline = new Timeline(edit, timelineContainer, { resizable: true });
await timeline.load();
// 7) Add keyboard controls
const controls = new Controls(edit);
await controls.load();
// 8) Add event handlers
edit.events.on("clip:selected", data => {
console.log("Clip selected:", data);
});
Your HTML must include both containers:
<div data-shotstack-studio></div>
<div data-shotstack-timeline></div>
Main Components
Edit
Edit is the runtime editing session and source of truth for document mutations.
import { Edit } from "@shotstack/shotstack-studio";
const edit = new Edit(templateJson);
await edit.load();
await edit.loadEdit(nextTemplateJson);
// Playback (seconds)
edit.play();
edit.pause();
edit.seek(2);
edit.stop();
// Mutations
await edit.addTrack(0, { clips: [] });
await edit.addClip(0, {
asset: { type: "image", src: "https://example.com/image.jpg" },
start: 0,
length: 5
});
await edit.updateClip(0, 0, { length: 6 });
await edit.deleteClip(0, 0);
// History
await edit.undo();
await edit.redo();
// Clip operations
await edit.deleteTrack(0);
// Output settings
await edit.setOutputSize(1920, 1080);
await edit.setOutputFps(30);
await edit.setOutputFormat("mp4");
await edit.setOutputResolution("hd");
await edit.setOutputAspectRatio("16:9");
await edit.setTimelineBackground("#000000");
// Read state
const time = edit.playbackTime;
const playing = edit.isPlaying;
const clip = edit.getClip(0, 0);
const track = edit.getTrack(0);
const snapshot = edit.getEdit();
const durationSeconds = edit.totalDuration;
Each html5 clip pre-renders all its frames when it loads, for smooth playback. An edit that is only captured with edit.captureFrame() can wait until it plays instead:
const edit = new Edit(templateJson, { html5Prerender: "on-play" });
Captured frames are the same either way. Until the edit plays, the canvas shows each html5 clip as a still of its frame at the playhead, in its layer and with its effects. Playback stays choppy until the frames are ready, so keep the default, "on-load", for an edit that someone watches.
edit.getPendingCaptures() returns { pending, total, progress }: how many html5 clips are still preparing smooth playback, out of those that will play pre-rendered frames, and how far along they are, from 0 to 1 by frames baked. Failed clips, and an "on-play" edit's clips before it plays, count in neither number. The timeline shows this as a ring around its play button and a ring in each preparing clip. A player of your own can read it on the capture events, and a few times a second in between, since progress moves without them:
const showPreparing = () => {
const { pending, progress } = edit.getPendingCaptures();
ring.hidden = pending === 0;
ring.style.setProperty("--progress", String(progress));
};
edit.events.on("clip:captureStarted", showPreparing);
edit.events.on("clip:captureCompleted", showPreparing);
edit.events.on("clip:captureFailed", showPreparing);
setInterval(showPreparing, 250);
showPreparing();
Events
Listen using string event names:
const unsubscribeClipSelected = edit.events.on("clip:selected", data => {
console.log("Selected clip", data.trackIndex, data.clipIndex);
});
edit.events.on("clip:updated", data => {
console.log("Updated from", data.previous, "to", data.current);
});
edit.events.on("playback:play", () => {
console.log("Playback started");
});
// Unsubscribe when no longer needed
unsubscribeClipSelected();
Available event names: