YouTube introduced Shorts in September 2020 and has been gaining popularity ever since. With Shorts, YouTube allows creators to post short, 60-second vertical videos.
These videos are perfect for sharing short clips from your longer videos. They can also help get your audience excited for upcoming content. Additionally, they allow you to join in on industry trends and more.
Creating YouTube Shorts videos is straightforward. What is a challenge is when you want to scale the process to create many videos at once. This tutorial will show you how to make automatically create YouTube shorts. You'll use the Shotstack API.
In this guide we'll show you how to generate YouTube Shorts, also called Reels, using a video editing API.
Shotstack is a platform that helps you automate video editing using its APIs. The process of editing and producing videos on a large scale can consume a lot of time. With Shotstack's automation tools, you can automatically create many AI-generated YouTube shorts videos.
YouTube Shorts are vertical videos. They're up to 60 seconds long and designed for quick viewing on mobile devices.
They're like TikTok videos or Instagram Reels and offer creators a way to make snappy, engaging content.
If you want to follow along with this guide, you will need the following:
The example video in this guide will have a background video, a voice over and captions. We used Shotstack's Create API) to generate the voice over.
We also created an SRT file from the audio, which is what we're using for the captions.
Start by preparing a JSON template. We have already made a template using Studio, our online video editor, to save you time. The template has merge fields for video, the AI-generated voice over, and captions, making it easy to reuse.
After making the template in the Studio, you can export the JSON and use the Edit API to create the videos.
Create a new shorts.json
file. Copy and save the JSON data below to it. This is the template we exported from the Studio.
{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "caption",
"src": "{{ CAPTIONS }}",
"background": {
"color": "#000000",
"padding": 50,
"borderRadius": 18,
"opacity": 0.6
},
"font": {
"color": "#ffffff",
"family": "Montserrat ExtraBold",
"size": 35,
"lineHeight": 1.5
},
"margin": {
"top": 0.1
}
},
"start": 0,
"length": "end"
}
]
},
{
"clips": [
{
"asset": {
"type": "video",
"src": "{{ VIDEO }}"
},
"start": 0,
"length": "auto"
}
]
},
{
"clips": [
{
"asset": {
"type": "audio",
"src": "{{ VOICEOVER }}"
},
"start": 0,
"length": "auto"
}
]
}
]
},
"output": {
"format": "mp4",
"aspectRatio": "9:16",
"resolution": "1080"
},
"merge": [
{
"find": "VIDEO",
"replace": "https://shotstack-ingest-api-stage-sources.s3.ap-southeast-2.amazonaws.com/irwdtighyk/zzz01j0s-23mvt-n9vbx-3fj7v-rx28x6/source.mp4"
},
{
"find": "VOICEOVER",
"replace": "https://shotstack-ingest-api-stage-sources.s3.ap-southeast-2.amazonaws.com/irwdtighyk/zzz01j0s-10wxr-5f7q5-2fpak-9me2z3/source.mp3"
},
{
"find": "CAPTIONS",
"replace": "https://shotstack-ingest-api-dev-sources.s3.ap-southeast-2.amazonaws.com/o2ko97ygqc/zzz01j0s-1ctry-b4adn-dhhnp-2pbs74/transcript.srt"
}
]
}
The JSON template includes three keys, the timeline
, output
, and merge
.
The timeline
includes three clips containing the various assets in the edit. They include a video, an audio (voice over), and an SRT file for the captions.
The output
specifies various preferences for the output video. The template uses an aspect ratio of 9:16 and a 1080p resolution. Ideal for creating YouTube Shorts videos.
The merge
array contains the dynamic elements in the template which includes a video, audio, and SRT file.
Another way of using the JSON is to save it as a template via the Studio panel on the dashboard. That way, you only need to use the template ID and merge fields without copying the entire JSON into your code.
Navigate to the directory with the shorts.json
file and run the following command to make a POST
request to the Edit API. Be sure to replace SHOTSTACK_API_KEY
with your sandbox API key
curl -X POST \
-H "Content-Type: application/json" \
-H "x-api-key: SHOTSTACK_API_KEY" \
-d @shorts.json \
https://api.shotstack.io/stage/render
If the request is successful, the API will respond with a response like the one below.
{
"success": true,
"message": "Created",
"response": {
"message": "Render Successfully Queued",
"id": "4a48a3f6-b445-4cb6-b143-dcd3e2c867e8"
}
}
Copy the value of response.id
and use it in the next step to check the render status of the video.
Send a GET
to the Edit API by running the command below. Replace RESPONSE_ID
in the command with the value of response.id
from the previous step. Also, make sure to replace SHOTSTACK_API_KEY
with your actual key.
curl -X GET \
-H "Content-Type: application/json" \
-H "x-api-key: SHOTSTACK_API_KEY" \
https://api.shotstack.io/stage/render/RESPONSE_ID?data=false
The API's response will look like the JSON below and will include a response.status
value. The render is complete if the value is done
. If not, wait for a few seconds and run the command again to make a new GET
request. You can also set up a webhook to receive notifications when the render completes or fails.
{
"success": true,
"message": "OK",
"response": {
"id": "4a48a3f6-b445-4cb6-b143-dcd3e2c867e8",
"owner": "irwdtighyk",
"plan": "sandbox",
"status": "done",
"error": "",
"duration": 17.68,
"billable": 17.68,
"renderTime": 29090.74,
"url": "https://shotstack-api-stage-output.s3-ap-southeast-2.amazonaws.com/irwdtighyk/4a48a3f6-b445-4cb6-b143-dcd3e2c867e8.mp4",
"poster": null,
"thumbnail": null,
"created": "2024-06-20T02:49:27.518Z",
"updated": "2024-06-20T02:50:03.303Z"
}
}
When the status
is equal to done
, the JSON response will include a URL that points to the rendered video. Copy and paste the URL in your browser to view or download the video.
In this guide, you've learned how to auto create YouTube Shorts video using an API. You can expand on this example to build more complex workflows or a complete YouTube automation system using Shotstack.
curl --request POST 'https://api.shotstack.io/v1/render' \
--header 'x-api-key: YOUR_API_KEY' \
--data-raw '{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "video",
"src": "https://shotstack-assets.s3.amazonaws.com/footage/beach-overhead.mp4"
},
"start": 0,
"length": "auto"
}
]
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 1280,
"height": 720
}
}
}'