How to Resize an Online Video in C/C++

Cloudmersive
2 min readAug 20, 2021

Aspect ratio dictates how your video looks in comparison with your original vision while also informing the viewer on what kind of video content they are watching. When resizing a video, but not changing the way that you wish it to be viewed, it is necessary to preserve that aspect ratio. This API will help you do exactly that using Java.

First off, we will install libcurl into our C/C++ project:

libcurl/7.75.0

Following the installation, we can input our video and API key into the below example 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/resize/preserveAspectRatio");
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, "frameRate: <integer>");
headers = curl_slist_append(headers, "quality: <integer>");
headers = curl_slist_append(headers, "extension: <string>");
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);

If you wish to dictate the dimensions of the output file, there are options for max width and height, frame rate, quality, and file extension. To retrieve your API key for the operation, register for a free account on the Cloudmersive website; this provides 800 monthly calls across our wide array of APIs.

--

--

Cloudmersive

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