How to Resize a Video in JavaScript

Cloudmersive
1 min readAug 13, 2021

--

Creating video content to post on your personal or business social media accounts usually requires a certain amount of editing and tailoring to meet the needs of each medium. If you need to resize a video and ensure that the original viewing experience remains intact, you will need to preserve the aspect ratio. By utilizing the following API in JavaScript, you will be able to resize a video while maintaining the original aspect ratio and encoding with very little effort on your part.

The first step of the process is to install jQuery:

bower install jquery

Once the installation is complete, you can set the optional parameters such as max width and height, frame rate, quality, etc. and call the function with the below code:

var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/video/resize/preserveAspectRatio",
"method": "POST",
"timeout": 0,
"headers": {
"fileUrl": "<string>",
"maxWidth": "<integer>",
"maxHeight": "<integer>",
"frameRate": "<integer>",
"quality": "<integer>",
"extension": "<string>",
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

And there you have it! The resized video will be ready to go at the end of the operation.

--

--

Cloudmersive

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