visit
The video shown above has been created with nothing other than code. No editing software has been used to design or render this video, with only a 40 line piece of JSON being needed to put together all individual elements to create a fully composited video using the .
enables video editing at scale. The API allows you to describe your video edit in JSON, and then use your favourite programming language to render hundreds to thousands of data-driven videos concurrently in the cloud.I wrote this guide to show you how you can use code instead of software to build cool and artistic videos, and I hope this small guide provides you with some inspiration to start creating your own videos.We’ll start off by creating something simple (such as compositing a title on a video clip), and then overlaying a soundtrack to give it some emotion. At the end, I’ll show you some more advanced features to finish off the video with some professional-looking effects.Sign up for an API key
In order to build your first video you’ll need to . This is completely free and will allow you to access all of Shotstack’s video editing functionalities to build videos and develop applications. After registering just log in via the Shotstack website to receive your API key.Curl vs Postman
This tutorial presumes a basic knowledge of interacting with API’s. For this guide we’ll be using but you can use any other application such as as well.Edit — An in Shotstack is essentially a JSON file describing how assets such as titles, video clips and images are arranged to create a video.
Timeline — The represents the entire duration of your video in seconds. For example, a 30 second video edit would have a 30 second timeline. Clips are placed along the timeline via a .
Tracks — A runs for the entire duration of the timeline and is used to layer clips on top of each other. For example, you can layer text on top of an image or a video clip. You can place multiple tracks on top of each other to create complex compositions.
Clips — A is a placeholder for an asset (titles, images, videos, audio, html, and ) and are positioned on the timeline (via a track) at specific time intervals. For example, you could add a clip that starts playing at the 5th second until the 10th second. Here you can also apply transitions, filters, and motion effects.
Assets — When creating a , you specify the type of asset to be displayed. This can be a , , , , or a . Each asset has options specific to its type. For example a title asset will have a type style, and a video asset might have a trim point to cut the start and end of the clip.
Output — The specifies the final render properties, with the API supporting mp4 video files and gifs in a range of resolutions such as HD, SD and mobile.
If this does not all make sense yet, it will all become clearer once we create a few examples.Create a text file called hello.json with the following contents:
{
"timeline": {
"background": "#000000",
"tracks": [
{
"clips": [
{
"asset": {
"type": "title",
"text": "Hello World",
"style": "future"
},
"start": 0,
"length": 5
}
]
}
]
},
"output": {
"format": "mp4",
"resolution": "sd"
}
}
curl -X POST \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d @hello.json \
//api.shotstack.io/stage/render
{
"success": true,
"message": "Created",
"response": {
"message": "Render Successfully Queued",
"id": "d2b46ed6-998a-4d6b-9d91-b8cf0193a655"
}
}
To check the status of the render run the following command, making sure to replace d2b46ed6–998a-4d6b-9d91-b8cf0193a655 with the id just copied.
curl -X GET \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
//api.shotstack.io/stage/render/d2b46ed6-998a-4d6b-9d91-b8cf0193a655
{
"success": true,
"message": "OK",
"response": {
"id": "d2b46ed6-998a-4d6b-9d91-b8cf0193a655",
"owner": "hckwccw3q3",
"plan": "sandbox",
"status": "done",
"url": "//s3-ap-southeast-2.amazonaws.com/shotstack-api-stage-output/hckwccw3q3/d2b46ed6-998a-4d6b-9d91-b8cf0193a655.mp4",
"data": {
"output": {...},
"timeline": {...}
},
"created": "2019-04-16T12:02:42.148Z",
"updated": "2019-04-16T12:02:51.867Z"
}
}
Replace the contents of hello.json with the following snippet:
{
"timeline": {
"soundtrack": {
"src": "//shotstack-assets.s3-ap-southeast-2.amazonaws.com/music/freepd/motions.mp3"
},
"background": "#000000",
"tracks": [
{
"clips": [
{
"asset": {
"type": "title",
"text": "Hello World",
"style": "future"
},
"start": 0,
"length": 15
}
]
},
{
"clips": [
{
"asset": {
"type": "video",
"src": "//shotstack-assets.s3-ap-southeast-2.amazonaws.com/footage/earth.mp4"
},
"start": 0,
"length": 15
}
]
}
]
},
"output": {
"format": "mp4",
"resolution": "1080"
}
}
In this example we have added a new soundtrack file as a second track (motions.mp3), in addition to the video asset earth.mp4. Both the title and video clip have a length of 15 seconds and start at 0 seconds, meaning we have composited these tracks on top of each other.
Note that the video asset is positioned below the title asset. This makes sure that the text is rendered on top of the video file and not hidden underneath.
Go ahead and use the previous Curl commands to post the video and check its status. You should end up with a video like the one below:This video is already a lot more interesting, but it could still do with a bit of refinement to give it a more professional touch.Replace the hello.json file with the following and post it to the API using the Curl command and check its status.
{
"timeline": {
"soundtrack": {
"src": "//shotstack-assets.s3-ap-southeast-2.amazonaws.com/music/freepd/motions.mp3",
"effect": "fadeOut"
},
"background": "#000000",
"tracks": [
{
"clips": [
{
"asset": {
"type": "title",
"text": "Hello World",
"style": "future",
"position": "left",
"size": "x-small"
},
"start": 4,
"length": 11,
"transition": {
"in": "fade",
"out": "fade"
},
"effect": "zoomIn"
}
]
},
{
"clips": [
{
"asset": {
"type": "video",
"src": "//shotstack-assets.s3-ap-southeast-2.amazonaws.com/footage/earth.mp4",
"trim": 5
},
"start": 0,
"length": 15,
"transition": {
"in": "fade",
"out": "fade"
}
}
]
}
]
},
"output": {
"format": "mp4",
"resolution": "sd"
}
}
Also published