How to Cut a Video to a Shorter Length in Node.JS

By trimming your videos, you can make sure that you are only keeping the content you need while excluding anything miscellaneous. This process can often be very time consuming and involved, however. With the following Cloudmersive API, you can trim your videos quickly and easily in Node.JS, making your next video project as painless as possible.

Image for post
Image for post

Run this command to install our client:

npm install cloudmersive-video-api-client --save

Or, you can also add this snippet to your package.json:

"dependencies": {
"cloudmersive-video-api-client": "^2.0.1"
}

Then, you can call the function, VideoCutVideo:

var CloudmersiveVideoApiClient = require('cloudmersive-video-api-client');
var defaultClient = CloudmersiveVideoApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveVideoApiClient.VideoApi();var opts = {
'inputFile': Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer), // File | Input file to perform the operation on.
'fileUrl': "fileUrl_example", // String | Optional; URL of a video file being used for conversion. Use this option for files larger than 2GB.
'startTime': new Date("2013-10-20T19:20:30+01:00"), // Date | Optional; Specify the desired starting time of the cut video in TimeSpan format.
'timeSpan': new Date("2013-10-20T19:20:30+01:00") // Date | Optional; Specify the desired length of the cut video in TimeSpan format. Leave blank to include the rest of the video. Maximum time is 4 hours.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.videoCutVideo(opts, callback);

Now, you’ll be able to help your next video project succeed, smoothly and effortlessly. You can find your personal API Key on the Cloudmersive website, giving you access to up to 800 calls across our library of APIs.

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store