How to Trim a Video using Node.js?

Trimming a video allows you to eliminate unnecessary or unwanted parts that are not relevant to your desired content. By cutting video at specified points, you can remove specific portions, like the first few seconds of a video, or divide a single video into multiple files. To accomplish this task using JavaScript, you'll need a video editing API. Here's how to do that using Node.js in just a few lines of code:

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

  source: new Creatomate.Source({
    outputFormat: 'mp4',
    elements: [
      new Creatomate.Video({
        source: '',
        trimStart: 1,
        trimDuration: 3,
}).then((renders) => {
Output Video

How it works: In order to perform video editing, install the Creatomate package from NPM. In this example, we're dealing with a single video in the scene, so there's only a single video element involved. We can reference any publicly hosted video URL without worrying about its format since the API will handle the conversion to MP4 automatically.

To trim the video, we make use of the "trim_start" and "trim_duration" properties. These properties enable us to specify the timestamps at which we would like to slice the video. In this case, we slice the video starting from 1 second into the beginning and keep a maximum duration of 3 seconds.

If you're interested in handling more advanced video editing tasks, be sure to explore the code video editor as well. This online tool not only provides the ability to programmatically trim videos but also streamlines a wide range of video editing tasks necessary for any kind of Node.js video processing. Check it out below.

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