How to Resize a Video Without Preserving Aspect Ratio in Node.JS

Cloudmersive
2 min readSep 11, 2020

--

With your audience spread across all current and new online media platforms, it’s important to optimize your brand’s presence. Online video content is ideal for sharing visuals, communicating information, and drawing in a wide audience. You may run into trouble, though, when video formatting changes across media platforms. The following Cloudmersive API will help you resize your video to fit any format by making slight changes to the aspect ratio as needed.

Our first step is to install the client software:

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

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

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

Then, you can call the function, VideoResizeVideoSimple:

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.
'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.
'extension': "extension_example" // String | Optional; Specify the file extension of the input video. This is recommended when inputting a file directly, without a file name. If no file name is available and no extension is provided, the extension will be inferred from the file data, which may cause a different extension to be used in the output.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.videoResizeVideoSimple(opts, callback);

Just following these simple steps will help you increase your video’s reach across all social media platforms. You can access your personal API Key on the Cloudmersive website; it will provide you with up to 800 call across our library of APIs with options to scale according to your organization’s needs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet