How to Add Text to Video using an API?

By adding text to a video, you can add text information to the video, such as titles, instructions, and lower thirds. To add text to videos programmatically, you can use a video editing API. Here's how to do it with just a single API call:

API Request
curl -s -X POST https://api.creatomate.com/v1/renders \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-binary @- << EOF
{
  "source": {
    "output_format": "mp4",
    "elements": [
      {
        "type": "video",
        "track": 1,
        "source": "https://cdn.creatomate.com/demo/mountains.mp4"
      },
      {
        "type": "text",
        "track": 2,
        "y": "63.12%",
        "width": "90.48%",
        "height": "15.12%",
        "x_alignment": "50%",
        "y_alignment": "50%",
        "text": "Add your custom text here. ✍️",
        "font_family": "Roboto",
        "font_weight": "500",
        "font_size_maximum": "10 vmin",
        "background_color": "#ffffff",
        "background_x_padding": "52%",
        "background_border_radius": "26%"
      }
    ]
  }
}
EOF
Output Video

How it works: This example shows how to use cURL to invoke the REST API for rendering text on top of the video. However, you can use any other tool or programming language to perform the API request. The video API uses JSON to describe the video that we would like to create. In this way, you can generate any kind of video, just by providing the right code instructions, and the API will do the rest.

In this case, we are creating a composition that contains two elements; a video element on track 1, and a text element on track 2. As each element is placed on a separate track, they will be displayed stacked on top of one another, similar to a visual editing tool, except that the editing is done programmatically.

As this is an automated process, we want to make sure the text scales automatically as well. You can accomplish this by providing relative units (%) while providing the location of the text. As a result, the text is automatically positioned according to the resolution of the video input.

There are several properties available to style the text, such as font, color, and background. This will allow you to style the text so that it is suitable for use with TikTok or Instagram. Furthermore, the text elements support emojis to make the text even more engaging and visually attractive.

To explore other styles and animations, use the online video editor below. This tool lets you create your own video designs, which can then be exported as JSON for easy integration into your automated workflows.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your application to create any kind of video – completely through code.

Related API Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free