How to Convert a Video to WEBM in Node.JS

Cloudmersive
2 min readSep 9, 2020

Online video has become a major resource for clients to find information and have their questions answered about both organizations and their processes. With the rise of this new medium, the WEBM file format has gained notoriety as it is compatible with most web browsers and is the sole format used for YouTube videos. The transition toward utilizing this new platform, however, can be a bit tricky without the proper tools. The following Cloudmersive API will show how you can easily convert your videos to WEBM format.

The first step is to install our client as shown below:

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

You can also add this snippet to your package.json, instead:

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

Now, you can call the function, VideoConvertToWebm:

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 original video width.
'maxHeight': 56, // Number | Optional; Maximum height of the output video, up to the original video width. Defaults to original video height.
'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 original video frame rate.
'quality': 56 // Number | Optional; Specify the quality of the output video, where 100 is lossless and 1 is the lowest possible quality with highest compression. Default is 50.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.videoConvertToWebm(opts, callback);

With that, you can optimize your videos for going viral on the most popular online video sites! Don’t forget to retrieve your personal API Key from the Cloudmersive website at no charge, giving you access up to 800 calls across any of our APIs.

--

--

Cloudmersive

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