Cloudinary supports delivering your videos as animated images in either GIF or WebP formats.
When deciding which version to use, consider the following:
Animated GIFs are universally supported. WebP is currently supported only in Chrome and Opera.
WebP supports 24-bit RGB color with an 8-bit alpha channel, compared to GIF's 8-bit color and 1-bit alpha.
WebP supports both lossy and lossless compression (a single animation can combine lossy and lossless frames), well-suited to animated images created from real-world videos. GIF only supports lossless compression.
WebP requires fewer bytes than GIF, ranging from 64% smaller for Animated GIF converted to lossy WebP, to 19% smaller for lossless WebP.
To deliver an animated GIF from any video stored in your Cloudinary account, you just change the file extension of the URL to .gif. Converting a video to animated GIF is normally done while resizing and cropping to match your site (usually scaling down). By default, the resulting animated GIF is generated from the whole video (up to 400 frames, at up to 10 frames per second) and is the same duration as the original video no matter how many frames are sampled. The resulting animated GIFs can also be further transformed like any other Cloudinary image.
To control how many frames are taken from the original video and the speed that they are displayed, use the video_sampling and delay parameters.
The video_sampling parameter (vs in URLs) determines how many frames to sample from the original video and can take one of the following values:
Integer - The total number of frames to sample from the original video. The frames are spread out over the length of the video, e.g. 25 samples one frame every 4%.
String - A float with an s appended representing the number of seconds between each frame to sample from the original video. e.g. 2.3s samples one frame every 2.3 seconds.
The delay parameter (dl in URLs) is used to set the time delay between the individual frames of the animated GIF, in milliseconds.
By default, animated GIFs with a resource_type of video run a single time. Use the loop effect (e_loop in URLs) to run in an infinite loop, or specify a loop value to run a limited number of loops. The loop number value is 0-based. For example, to set your GIF to loop exactly 3 times, set the loop effect value to 2 (e_loop:2 in URLs).
Examples of generating animated GIFs from uploaded videos:
Using a sample of 40 frames from the original video and setting a delay of 100 milliseconds between the frames of the resulting animated GIF, which is scaled down to a height of 200 pixels and runs in an infinite loop:
Sampling one frame every 1.1 seconds from the original video and setting a delay of 200 milliseconds between the frames of the resulting animated GIF, which is scaled down to a width of 200 pixels and loops 3 times:
Delivering an animated WebP that from an uploaded video is similar to generating an animated GIF as described above, except that you also need to enable the awebp and animated flags (fl_awebp and fl_animated in URLs). You can generate animated WebPs at up to 30 frames per second.
For example, generating an animated WebP from the uploaded mp4 video named dog, using a sample of 10 frames from the original video and setting a delay of 100 milliseconds between the frames of the resulting animated WebP, which is also scaled down to a width of 250 pixels:
You can also create animated images from videos together with the auto format and the animated flag parameters (f_auto and fl_animated in URLs). Adding these parameters will deliver an animated WebP to browsers that support the format, and fall back to delivering an animated GIF to browsers that don't support the format. See the blog post on animated WebP for more information.
For example, to deliver an animated WebP of the mp4 video named dog to supported browsers, but fall back to animated GIF for unsupported browsers: