Create Videos using Code

With the help of a programming language such as JavaScript, PHP, Ruby, Python, it is easy to create videos programmatically. Automate videos for social media, marketing, or personalization, and produce any kind of data-driven video at scale – with the tech stack you're already familiar with.

  • Create video using any coding language
  • Compose video using JSON
  • Automate video editing and production

How to Create Videos with Code

There are two ways to create video with code; either by using a video template or by composing the video entirely in code. The template-based approach involves creating a placeholder design in the video editor, and then rendering the template with custom data. The second approach involves generating a video script, which provides greater flexibility and control over the video creation process.

1Create a video template

No matter if you're generating a video from a template or coding it from scratch, the online video editor provides an easy way to get started.

The editor allows you to design video templates that can be accessed using the programming interface and SDKs. This allows you to automate the entire production process through the use of your own software.

Templates created using the editor are composed of JSON. As soon as you've finished building the video foundation, you can export its JSON and integrate it into your application.

{
  output_format: "mp4",
  frame_rate: 30,
  width: 1080,
  height: 1080,

  elements: [
    {
      type: "video",
      track: 1,
      duration: 3,
      source: "https://example.com/video.mp4",
      animations: [
        { ... }
      ]
    },

    {
      type: "text",
      width: "90%",
      height: "10%",
      text: "Your overlay text here",
      font_family: "Cabin",
      font_weight: "700",
      fill_color: "#fff"
    },

    { ... }
  ],
}

2Generate video from JSON

Think of JSON as the source code for the video. It describes the entire video from beginning to end, and is composed of elements (texts, images, audio clips, etc.) that can be styled, transformed, and animated. It's similar to HTML, React, Angular, or another component-based architecture, but instead of webpages, you'll use code to generate video.

With JSON's flexibility and broad support for any programming language (JavaScript, PHP, Ruby, Python, etc.), you can easily generate any kind of code-driven video with techniques you're already familiar with. This gives you pixel-perfect control over the video rendering, all the while using your own technology stack.

3Build video-powered applications

Having set up a template or JSON file, you can use the REST API to generate MP4 videos. All heavy lifting is performed in the cloud, so there is no need to maintain any video processing infrastructure. The API runs on an auto-scaling infrastructure that provides unlimited processing capabilities to handle any high-demand application. Therefore, even if you are developing the next groundbreaking video application, you will not need to worry about server capacity, as the infrastructure will grow with your application.

Using Creatomate's video SDK, you can easily create video editing apps, with many libraries and examples to help you get started quickly. If you are creating a web-based video editor tool, you might also be interested in the Preview SDK, which is a JavaScript library that lets you render video previews inside the browser.

Want to try it yourself? Get started for free in minutes:

Frequently asked questions

How can I create video by code?

A video can be generated through code by using an API (application programming interface) capable of processing video-related operations. One such API is Creatomate. It uses a declarative language that describes the entire video from beginning to end, using JSON as the data format. In this JSON, you can define the components to be included in the video (such as texts, images, footage, etc.) as well as timing, filters, effects, animations, and keyframes. This gives you pixel-perfect control over the output video using a developer-friendly abstraction.

Read through the documentation to learn more about this JSON-to-video format. You can also generate this JSON code with the online video editor.

What kind of video can be generated by code?

No matter what video operation you want to do – processing user-generated video content, generating real estate videos, product videos, marketing ads, social media videos – you can use the Creatomate API to programmatically create video for your application. Its declarative JSON script lets you edit and create videos however you like, with pixel-perfect precision. Have a look at the video editor to see what is possible. This online tool lets you create your own video templates, as well as generate custom JSON code for dynamic video editing (such as stitching, trimming, resizing, etc.) that can be used in any programming language.

What's the best code-driven video API?

In our opinion, the Creatomate API provides the most comprehensive and cost-effective code-driven video generation solution on the market today. Compared to all other products on the market, it features the most advanced video editing capabilities, as well as the best video tooling for setting up video generation applications, such as the online editor that lets you quickly create your own video templates. Take a look at this article that compares all the video editing APIs.

Which code languages can be used to create video?

JSON is a universal data format that can be used by any programming language. No matter what you're using, like JavaScript, PHP, Python, Ruby, .NET, Go, C++, you can create video programmatically. In other words, you are free to create and edit video in your favorite programming language without making any changes to your technology stack. Additionally, the JSON format is very lightweight and requires no software dependencies, so there will be no overhead to your software.

How to build a video editor by code?

Video editing by code involves software that can import source files (like images, video footage, audio clips, custom fonts, etc.), apply filters and styling, render animations, assemble the video, and encode the pixel data into a format like H.264. This is a very CPU-intensive process that is very difficult to scale up. The good news is that a managed video cloud service can do all this for you for a fraction of the cost of running your own infrastructure. One such cloud rendering infrastructure is Creatomate, whose REST API has been built by developers, for developers, and is compatible with all programming languages.

Can't I just use FFmpeg?

FFmpeg is a powerful command-line tool, but its capabilities in terms of styling, text support, animations, effects, and keyframes are limited. It's also challenging to run at scale. Although you could set up a cloud-based infrastructure running FFmpeg that scales on demand, this method would be more complex and expensive than using Creatomate's API. Plus, you'd have to build and manage your own video rendering software. In fact, that's why we built Creatomate – to make building video solutions easier, so you can focus on building great video editing applications rather than worrying about low-level infrastructure.

How much does a video API cost?

In comparison to building your own video editing infrastructure, Creatomate's API costs much less. Its pricing starts at about the same as a single AWS EC2 server. However, an EC2 server can only handle one video at a time and needs maintenance, not to mention you have to develop your own rendering software.

Quickly get started

Learn how to automate your videos by following our practical tutorials.

Start automating today

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