How to Blur the Background of a Video using Node.js?

Most smartphone users record their videos vertically. But what if you need a landscape-oriented video? A popular way to convert videos into landscape format is by blurring the edges. To do this using JavaScript, you need a video editing API. Here's how to blur a video's background using Node.js in just a few lines of code:

Input Code
const Creatomate = require('creatomate');
const client = new Creatomate.Client('Your API Key');

client.render({
  source: new Creatomate.Source({
    output_format: 'mp4',
    width: 1920,
    height: 1080,
    elements: [

      new Creatomate.Video({
        clip: true,
        colorOverlay: 'rgba(0,0,0,0.15)',
        blurRadius: 57,
        source: 'https://cdn.creatomate.com/demo/vertical.mp4',
        volume: '0%',
      }),

      new Creatomate.Video({
        source: 'https://cdn.creatomate.com/demo/vertical.mp4',
        fit: 'contain',
      }),
    ],
  }),

}).then((renders) => {
  console.log(renders);
});
Output Video

How it works: This method works with any type of video format, like square, portrait, or vertical. It doesn't matter what resolution the video is, it will automatically fit into the desired output size.

Start by installing the Creatomate library from NPM. With this package installed, we can easily create videos by defining a video scene in JSON format.

To begin with, decide on an output resolution, such as 1080p (1920 x 1080). Then, define two video elements. The first element is the blurred background video. You can adjust the amount of blur by adjusting the "blur_radius" property. You can also darken it a bit using the "color_overlay" property. Don't forget to mute the video using the "volume" property, to remove the audio track from the background element.

The second element is the foreground video. Make sure the "fit" property is set to "contain", so it fits perfectly within the edges of the final video. Note that neither element has a duration specified. This is because the output video is calculated automatically, so you don't have to specify it beforehand.

If you prefer a visual editor, be sure to take a look at the video editor. With this online tool, you can design your own video templates in an interactive editor, then export those templates as JSON code for use in your Node.js projects.

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 Node.js application to create any kind of video – completely through code.

Related Node.js Video Editing Questions

Start automating today

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