Convert a Video to WEBM Format in C/C++
Online videos have become a major resource for businesses to educate and inform both employees and customers. Due to the popularity of the medium, a new file format was developed that is compatible with almost all web browsers — the WEBM format. To avoid the difficulties that may arise when attempting to manually convert a video to the new format, we will demonstrate how to automatically convert your videos to WEBM by using an API in C/C++.
We will begin by installing libcurl in our C/C++ project:
libcurl/7.75.0
Now, we are ready to call the 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/webm");
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! Quick and easy.