Video Conversion API: Convert a Video to an Animated GIF Format using Java

With our Video to GIF conversion API, not only can you convert from a wide variety of video formats, but you can also specify output details for the new GIF, too (e.g., frame rate, start time, time span, and more).

To incorporate this API with Java, follow instructions below to install with Maven. Note that the maximum output file size is 50 GB.

First, add a reference to the repository in pom.xml:


Next, add one to the dependency:


To finish up, include the import classes at the top of the function and call the API:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.VideoApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
VideoApi apiInstance = new VideoApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
String fileUrl = "fileUrl_example"; // String | Optional; URL of a video file being used for conversion. Use this option for files larger than 2GB.
Integer maxWidth = 56; // Integer | Optional; Maximum width of the output video, up to the original video width. Defaults to 250 pixels, maximum is 500 pixels.
Integer maxHeight = 56; // Integer | Optional; Maximum height of the output video, up to the original video width. Defaults to 250 pixels, maximum is 500 pixels.
Boolean preserveAspectRatio = true; // Boolean | Optional; If false, the original video's aspect ratio will not be preserved, allowing customization of the aspect ratio using maxWidth and maxHeight, potentially skewing the video. Default is true.
Integer frameRate = 56; // Integer | Optional; Specify the frame rate of the output video. Defaults to 24 frames per second.
OffsetDateTime startTime =; // OffsetDateTime | Optional; Specify the desired starting time of the GIF video in TimeSpan format.
OffsetDateTime timeSpan =; // OffsetDateTime | Optional; Specify the desired length of the GIF video in TimeSpan format. Limit is 30 seconds. Default is 10 seconds.
try {
byte[] result = apiInstance.videoConvertToGif(inputFile, fileUrl, maxWidth, maxHeight, preserveAspectRatio, frameRate, startTime, timeSpan);
} catch (ApiException e) {
System.err.println("Exception when calling VideoApi#videoConvertToGif");

Now you’re good to go. Check out our other articles for dozens of useful APIs available in Java, Python, C#, and more.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


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