Create videos with API
This documentation shows an example of creating a single video using Shakr API.
Requirements
- Server access token for authentication.
- Information of creative template.
Fetch Template mapping specification
To change design elements in the template you've chosen, you can refer to template's mapping specification. Mapping specification includes information including design elements that can be edited, and you can construct a mapping
object which you can use to make an API call to create RenderSession.
For this example, we will use a template called Skin Company, a cheerful, simple-to-create template from Shakr Template Library.
- cURL
- Elixir
curl 'https://api.shakr.com/v2/template_style_versions/TEMPLATE_STYLE_VERSION_ID/specs' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer SERVER_ACCESS_TOKEN'
{
"style_version": {
... // Mapping specification
}
}
request = %HTTPoison.Request{
url: "https://api.shakr.com/v2/template_style_versions/TEMPLATE_STYLE_VERSION_ID/specs",
method: :get,
headers: [
{"Authorization", "Bearer SERVER_ACCESS_TOKEN"}
]
}
with {:ok, %{status_code: 200} = response} <- HTTPoison.request(request),
{:ok, decoded_json} <- Jason.decode(response.body) do
# Mapping Specification
IO.inspect(decoded_json["style_version"])
end
Sample mapping specification
Here is a sample mapping specification of Skin Company template.
- Summary
- Full
{
"style_version": {
"id": "xQGAFq",
"editables": {
"c_01": {
"input_type": "color",
"example_text": "EEADA7",
"stillcut": "stillcut_01",
"fonts": [
"Montserrat-Regular"
]
},
...
"t_01": {
"input_type": "text",
"example_text": "Skin care",
"stillcut": "stillcut_01",
"fonts": [
"AbrilFatface-Regular"
]
},
...
"(Footage)/USER/logo_01.png": {
"input_type": "image",
"width": 550,
"height": 180,
"stillcut": "stillcut_01"
},
...
},
"fonts": [
"Montserrat-Regular",
"AbrilFatface-Regular",
"Montserrat-Medium"
]
}
}
{
"style_version": {
"id": "xQGAFq",
"editables": {
"c_01": {
"input_type": "color",
"example_text": "EEADA7",
"stillcut": "stillcut_01",
"fonts": [
"Montserrat-Regular"
]
},
"c_02": {
"input_type": "color",
"example_text": "394359",
"stillcut": "stillcut_01",
"fonts": [
"Montserrat-Regular"
]
},
"c_03": {
"input_type": "color",
"example_text": "FFFFFF",
"stillcut": "stillcut_01",
"fonts": [
"Montserrat-Regular"
]
},
"t_01": {
"input_type": "text",
"example_text": "Skin care",
"stillcut": "stillcut_01",
"fonts": [
"AbrilFatface-Regular"
]
},
"t_02": {
"input_type": "text",
"example_text": "that fits",
"stillcut": "stillcut_01",
"fonts": [
"AbrilFatface-Regular"
]
},
"t_03": {
"input_type": "text",
"example_text": "just for you",
"stillcut": "stillcut_01",
"fonts": [
"AbrilFatface-Regular"
]
},
"t_04": {
"input_type": "text",
"example_text": "only at ",
"stillcut": "stillcut_02",
"fonts": [
"Montserrat-Medium"
]
},
"t_05": {
"input_type": "text",
"example_text": "START FREE TRIAL",
"stillcut": "stillcut_02",
"fonts": [
"AbrilFatface-Regular"
]
},
"(Footage)/USER/logo_01.png": {
"input_type": "image",
"width": 550,
"height": 180,
"stillcut": "stillcut_01"
},
"(Footage)/USER/user_02.jpg": {
"input_type": "image",
"width": 1350,
"height": 1080,
"stillcut": "stillcut_02"
}
},
"fonts": [
"Montserrat-Regular",
"AbrilFatface-Regular",
"Montserrat-Medium"
]
}
}
From above, the most important part would be the editables
object. As the name suggests, it contains elements that can be edited, such as images, videos, and text. You can check the type of editables by referring to input_type
.
See also
Build your mapping data
After getting mapping specification, you can now build your mapping data and fill in text or media assets. Since the sample template contains text and image editables, we'll explore how to build editable data for those two types.
Text editables
Text editables are the simplest form of editables that display text in the video. If you want to assign My video text
text value to t_01
text editable, you can add it to your mapping data like below.
{
"t_01": {
"source": { "text": "My video text" }
}
}
Image editables
Image editables display images within a video and can be utilized in various ways such as photos of a product or brand logos. You need to assign URL of the image file you want to use, and how you would like to handle the image. (i.e. Cropping) For more information, please refer to Image editable documentation.
If you want to place https://via.placeholder.com/1280x720.jpg
image onto (Footage)/USER/logo_01.png
editable and fill in the display area without a gap, you can add it to your mapping data like below.
{
"(Footage)/USER/logo_01.png": {
"source": {
"remote_url": "https://via.placeholder.com/1280x720.jpg"
},
"transform": {
"crop_strategy": "cover"
}
}
}
Go through all editables on mapping specification, and your mapping data is complete.
See also
- Build a mapping: Describes additional editable types, and more.
Create a RenderSession
Since now we have all the info needed to create a video, we can now create a RenderSession
. mapping
object contains template_style_version_id
, which we acquired beforehand, and resources
object, which contains resources information within the mapping. Let's look at a sample request below.
- cURL
- Elixir
curl 'https://api.shakr.com/v2/render_sessions' \
-X POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer SERVER_ACCESS_TOKEN'
--data-raw '{
"title": "My New Video (Using Skin Company template)",
"render": "preview",
"mapping": {
"template_style_version_id": "xQGAFq",
"resources": {
"t_01": { "source": { "text": "Skin beauty" } },
"t_02": { "source": { "text": "delivered" } },
"t_03": { "source": { "text": "just for you" } },
"t_04": { "source": { "text": "only at " } },
"t_05": { "source": { "text": "EXCLUSIVE TRIAL OFFER" } },
"(Footage)/USER/logo_01.png": {
"source": { "remote_url": "https://via.placeholder.com/550x180.png" },
"transform": { "crop_strategy": "cover" }
},
"(Footage)/USER/user_02.jpg": {
"source": { "remote_url": "https://via.placeholder.com/1680x1050.jpg" },
"transform": { "crop_strategy": "cover" }
}
}
}
}'
{
"render_session": {
"id": "RENDER_SESSION_ID",
"title": "My New Video (Using Skin Company template)",
"status": "preview_rendering",
"render_progress": 0,
"thumbnails": [],
"video_url": null,
"errors": [],
"created_at": "2030-01-01T07:20:22.527Z",
"updated_at": "2030-01-01T07:20:22.619Z",
"mapping": {
"id": "MAPPING_ID",
"template_style_version_id": "xQGAFq",
"resources": {
"t_01": { "source": { "text": "Skin beauty" } },
"t_02": { "source": { "text": "delivered" } },
"t_03": { "source": { "text": "just for you" } },
"t_04": { "source": { "text": "only at " } },
"t_05": { "source": { "text": "EXCLUSIVE TRIAL OFFER" } },
"(Footage)/USER/logo_01.png": {
"source": { "remote_url": "https://via.placeholder.com/550x180.png" },
"transform": { "crop_strategy": "cover" }
},
"(Footage)/USER/user_02.jpg": {
"source": { "remote_url": "https://via.placeholder.com/1680x1050.jpg" },
"transform": { "crop_strategy": "cover" }
}
}
},
"audio_tracks": {},
"font_changes": {},
"source_uploads": [],
"fonts": []
}
}
params = %{
title: "My New Video (Using Skin Company template)",
render: "preview",
mapping: %{
template_style_version_id: "xQGAFq",
resources: %{
"t_01" => %{source: %{text: "Skin beauty"}},
"t_02" => %{source: %{text: "delivered"}},
"t_03" => %{source: %{text: "just for you"}},
"t_04" => %{source: %{text: "only at "}},
"t_05" => %{source: %{text: "EXCLUSIVE TRIAL OFFER"}},
"(Footage)/USER/logo_01.png" => %{
source: %{remote_url: "https://via.placeholder.com/550x180.png"},
transform: %{crop_strategy: "cover"}
},
"(Footage)/USER/user_02.jpg" => %{
source: %{remote_url: "https://via.placeholder.com/1680x1050.jpg"},
transform: %{crop_strategy: "cover"}
}
}
}
}
request = %HTTPoison.Request{
url: "https://api.shakr.com/v2/render_sessions",
method: :post,
headers: [
{"Content-Type", "application/json"},
{"Authorization", "Bearer SERVER_ACCESS_TOKEN"}
],
body: Jason.encode!(params)
}
render_session =
with {:ok, %{status_code: 201} = response} <- HTTPoison.request(request),
{:ok, decoded_json} <- Jason.decode(response.body) do
decoded_json["render_session"]
end
When the request is successful, you can see that render_session
object is successfully returned.
See also
Check rendered video
When status
property in RenderSession
object changes to preview_rendered
, it means that the video is ready. You can fetch the completed video's URL by looking into video_url
property.
- cURL
- Elixir
curl 'https://api.shakr.com/v2/render_sessions/RENDER_SESSION_ID' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer SERVER_ACCESS_TOKEN'
{
"render_session": {
"id": "<RENDER_SESSION_ID>",
"title": "My New Video",
"status": "preview_rendered",
"render_progress": 100,
"thumbnails": ["IMAGE_URL"],
"video_url": "VIDEO_URL",
...
}
}
request = %HTTPoison.Request{
url: "https://api.shakr.com/v2/render_sessions/RENDER_SESSION_ID",
method: :get,
headers: [
{"Authorization", "Bearer SERVER_ACCESS_TOKEN"}
]
}
with {:ok, %{status_code: 200} = response} <- HTTPoison.request(request),
{:ok, decoded_json} <- Jason.decode(response.body) do
render_session = decoded_json["render_session"]
if render_session["status"] === "preview_rendered" do
# completed video's URL
IO.puts(render_session["video_url"])
end
end
Congratulations, now you have made a video using Shakr API! 🎉
See also
More features of Shakr API
- You can use additional types of editables, such as Font Editables.
- Automated Video Delivery enables automated export of completed videos to a cloud storage of your choice.
- Automated Video Delivery webhook delivers webhook notifications to your web server after Automated Video Delivery is completed.