How to Trim a Video using an API?

Video trimming involves cutting an existing video into shorter fragments. A purpose of this is to make a clip that can be easily shared on social media from a longer video recording. Here is an example of how to trim a video using an API:

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",
        "source": "https://cdn.creatomate.com/demo/mountains.mp4",
        "trim_start": 1,
        "trim_duration": 3
      }
    ]
  }
}
EOF
Output Video

How it works: In this example, we're using Creatomate's video editing API. This REST API works by running video operations that are defined as JSON. All the operations are done in the cloud, and once the video is created, it's returned as an MP4 file.

As shown in the JSON code, we are defining a simple composition using a single video element with the "trim_start" and "trim_duration" attributes. This trims the video clip at 1 second from the beginning and for a duration of 3 seconds.

If you want to perform more advanced video editing tasks, try out the video editor below. Aside from trimming videos by API, this online tool also simplifies other video editing tasks, such as adding watermarks, captions, and merging videos, all of which can be performed through a RESTful API.

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