Sign up for free

Video clipping & Trimming

In some cases, you just need to upload a smaller piece of a video, but you would like to do that programmatically, without resorting to editing programs.

api.video allows you to clip a video to upload only specific parts of the video. You will be able to specify the start and end time of the clip before you upload the source video to api.video.

A diagram that shows the process of clipping a videoA diagram that shows the process of clipping a video

How does video clipping work?

The videos are clipped by the definition of the object. When you create a video object, you can pass the clip parameter, which will take the start and end time of the clip. Once the object is created with the clip time, you can upload the video to the video object.

Usage

You can use one of the API clients offered by api.video. You can find the list of clients in the api.video API Client catalog.

You can also find more information on the /videos endpoints on the API reference page.

For this example, let’s assume that we have a video file that is 00:10:00 in length and we would like to get only 5 seconds of the clip between the 20th to the 22nd second of the video.

Clipping and trimming videos from local file or URL source

Once you’ve determined what video you would like to clip and trim, you need to create a video object with the clip parameter.

Clipping a video
// Documentation: https://github.com/apivideo/api.video-nodejs-client/blob/main/doc/api/VideosApi.md#create

const client = new ApiVideoClient({ apiKey: "YOUR_API_KEY" });

// create a video using all available attributes
const video = await client.videos.create({
  title: "My video", // The title of your new video.
  clip: { "startTimecode" : "00:00:20", "endTimecode": "00:00:22" } // the clip start and end time
});

Once the object is created, all you have to do is just upload the video to the object:

Uploading a video
const file = './my-video.mp4'; // The path to the video you would like to upload. The path must be local. If you want to use a video from an online source, you must use the "/videos" endpoint and add the "source" parameter when you create a new video.
const videoId =  video.id    
const upload = await client.videos.upload(videoId, file)

Once the video is uploaded and trancoded it will only include the segment of the clip that you have configured.

Was this page helpful?