How to Convert a Video File to MP4 in C/C++

Cloudmersive
2 min readJun 8, 2021

--

If you need to convert a video file to the video-editing favorite MP4 format, this tutorial will offer a simple solution to fit your needs. Utilizing the following API in C/C++, you will be able to automatically transform a wide array of video file formats to MP4. This simple process uses 1 API call per 10 MB of file size and 1 API call per additional minute of processing time over 5 minutes, up to a maximum of 25 minutes.

Now to perform the operation, we will first install libcurl:

libcurl/7.75.0

Then, we can call the conversion function with the following code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/video/convert/to/mp4");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "fileUrl: <string>");
headers = curl_slist_append(headers, "maxWidth: <integer>");
headers = curl_slist_append(headers, "maxHeight: <integer>");
headers = curl_slist_append(headers, "preserveAspectRatio: <boolean>");
headers = curl_slist_append(headers, "frameRate: <integer>");
headers = curl_slist_append(headers, "quality: <integer>");
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);

And that’s it — your new MP4 file will be ready to fulfill your sharing or editing requirements.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet