Build video applications and workflows using a Python video editing library and the Shotstack API. Python video processing made easy.
Over 20,000 Businesses & Developers from 119 Countries Trust Shotstack
Edit videos using the Shotstack Python video editing library. The fully managed API makes it quick and easy to build video based applications in days, not months.
Available as an open source Python package on PyPI or from GitHub. The demo repository is also available that shows you how to get started generating video using Python. The SDK and demo projects connect to the Shotstack video editing API - a cloud hosted, fully managed video editing platform.
Using Shotstack and Python you can cut and trim videos, stitch clips, add transitions, filters and effects. Merge videos, images and audio files using Python, the language you are familiar with.
The Shotstack Python video editing library is available for Python version 3 and can be installed from PyPI.
pip install shotstack_sdk
Import the library in to your script.
import shotstack_sdk as shotstack
Import the editing features needed for your video edit.
from shotstack_sdk.api import edit_api
from shotstack_sdk.model.video_asset import VideoAsset
from shotstack_sdk.model.clip import Clip
from shotstack_sdk.model.track import Track
from shotstack_sdk.model.timeline import Timeline
from shotstack_sdk.model.output import Output
from shotstack_sdk.model.edit import Edit
Configure the API client to use either the free developer sandbox or the v1 production API.
configuration = shotstack.Configuration(host = 'https://api.shotstack.io/stage')
Copy your API key for the sandbox or v1 environment from the dashboard and set the `DeveloperKey`. You should load the key using environment variables in a production environment.
configuration.api_key['DeveloperKey'] = 'H7jKyj90kd09lbLOF7J900jNbSWS67X87xs9j0cD'
A simple use case for Shotstack is trim a video. In the example below the first 3 seconds are trimmed from the start of the skater.hd.mp4 video. The video then plays for 8 seconds. The start point of 0 plays the click form the start of the timeline, i.e. immediately.
video_asset = VideoAsset(
src = "https://s3-ap-southeast-2.amazonaws.com/shotstack-assets/footage/skater.hd.mp4",
trim = 3.0
)
video_clip = Clip(
asset = video_asset,
start = 0.0,
length = 8.0
)
Videos, images and text can be layered on top of each other using tracks. In this example there is only one video added to a single track.
track = Track(clips=[video_clip])
Tracks are added to the timeline. The timeline accepts an array of tracks as well as a background color.
timeline = Timeline(
background = "#000000",
tracks = [track]
)
The video output specification is defined including the resolution and format, such as an mp4 SD video.
output = Output(
format = "mp4",
resolution = "sd"
)
Finally everything is put together as an edit, including the timeline and output format.
edit = Edit(
timeline = timeline,
output = output
)
The SDK post_render method prepares the edit to the Shotstack JSON specification and posts it to the API. The response includes a render ID of the video which renders in the background.
api_response = api_instance.post_render(edit)
id = api_response['response']['id']
print(f">> python examples/status.py {id}")
Videos render in the background and can take a few seconds to minutes depending on the length. The status can be polled using the id returned in step 9.
api_response = api_instance.get_render(id)
status = api_response['response']['status']
if status == "done":
url = api_response['response']['url']
print(f">> Asset URL: {url}")
After a few seconds the render will complete and the status request will return the URL of a video file.
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
Free tier (no watermarks)
No credit card required