How to Convert a Video to GIF in Node.JS

In solid marketing strategy, gaining audience recognition and conveying your message quickly and efficiently is key. Using GIFs as part of your online outreach will check both boxes, as the format is compatible across most social media platforms and pulls interest without losing your audience’s attention as a longer-form video might. You can use this Cloudmersive API in Node.JS to convert any of your videos to GIF format and upgrade your online media marketing.

Image for post
Image for post

The first step in the conversion process is installing the client software:

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

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

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

Then, you can call our function, VideoConvertToGif:

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.
'maxWidth': 56, // Number | Optional; Maximum width of the output video, up to the original video width. Defaults to 250 pixels, maximum is 500 pixels.
'maxHeight': 56, // Number | Optional; Maximum height of the output video, up to the original video width. Defaults to 250 pixels, maximum is 500 pixels.
'preserveAspectRatio': true, // Boolean | Optional; If false, the original video's aspect ratio will not be preserved, allowing customization of the aspect ratio using maxWidth and maxHeight, potentially skewing the video. Default is true.
'frameRate': 56, // Number | Optional; Specify the frame rate of the output video. Defaults to 24 frames per second.
'startTime': new Date("2013-10-20T19:20:30+01:00"), // Date | Optional; Specify the desired starting time of the GIF video in TimeSpan format.
'timeSpan': new Date("2013-10-20T19:20:30+01:00") // Date | Optional; Specify the desired length of the GIF video in TimeSpan format. Limit is 30 seconds. Default is 10 seconds.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.videoConvertToGif(opts, callback);

With this, you can boost your presence online and increase the sharing power of your content. You’ll find your personal API Key on the Cloudmersive website, providing access to 800 calls across all of our 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