How to Convert a Video to MP4 in JavaScript

Cloudmersive
1 min readJun 1, 2021

The MP4 file format is known for its ability to handle complex audio and deluxe features/additions while maintaining superior quality and fidelity. If you have a video file you want to transform into this easy to use, compatible format, we have something that can simplify the process. The following API will allow you to automatically convert any video file to MP4 in JavaScript; it even includes optional parameters such as aspect ratio and frame rate that you can use to fine-tune the output.

To begin the process, we will install the jQuery library:

bower install jquery

Now, we are ready to call the conversion function with the following code:

var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/video/convert/to/mp4",
"method": "POST",
"timeout": 0,
"headers": {
"fileUrl": "<string>",
"maxWidth": "<integer>",
"maxHeight": "<integer>",
"preserveAspectRatio": "<boolean>",
"frameRate": "<integer>",
"quality": "<integer>",
"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 that’s it! Your new video will be returned and ready for immediate use.

--

--

Cloudmersive

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