Converting videos to animated images
Last updated: Sep-02-2024
Cloudinary supports delivering your videos as animated images in either AVIF
, GIF
, PNG
or WebP
formats.
When deciding which format to use, consider the following:
- Animated GIFs are universally supported. Animated WebPs, animated AVIFs and animated PNGs are supported on most, but not all, browsers.
- Animated AVIF is based on the AV1 video codec that was released in 2019 and shares the same compression and quality levels.
- Animated PNG, WebP and AVIF support 24-bit RGB color with an 8-bit alpha channel, compared to GIF's 8-bit color and 1-bit alpha.
- AVIF and WebP support 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 and PNG only support lossless compression.
- AVIF requires fewer bytes than WebP, which itself requires fewer bytes than GIF and PNG.
- Animated GIF converted to animated AVIF can provide over 90% byte savings.
- Animated GIF converted to animated WebP can provide between 64% byte savings (lossy WebP), to 19% byte savings (for lossless WebP).
- There are different transformation counts for different animated formats.
Delivering animated GIFs
To deliver an animated GIF from any video stored in your Cloudinary product environment, 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 animated WebP files
To deliver an animated WebP from an uploaded video, change the file extension to .webp
and set 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
, and also scaling it down to a width of 250 pixels:
![Animated WebP created from the dog video Animated WebP created from the dog video](https://res.cloudinary.com/demo/video/upload/c_scale,w_250/fl_animated,fl_awebp/dog.webp)
See the blog post on animated WebP for more information.
Delivering animated PNG files
To deliver an animated PNG from an uploaded video, change the file extension to .png
and set the apng
and animated
flags (fl_apng
and fl_animated
in URLs).
For example, generating an animated PNG from the uploaded MP4 video named dog
, and also scaling it down to a width of 250 pixels:
![Animated PMG created from the dog video Animated PMG created from the dog video](https://res.cloudinary.com/demo/video/upload/c_scale,w_250/fl_animated,fl_apng/dog.png)
Delivering animated AVIF files
To deliver an animated AVIF from an uploaded video, change the file extension to .avif
and set the animated
flag (fl_animated
in URLs).
For example, generating an animated AVIF from the uploaded MP4 video named dog
, and also scaling it down to a width of 250 pixels:
![Animated AVIF created from the dog video Animated AVIF created from the dog video](https://res.cloudinary.com/demo/video/upload/c_scale,w_250/fl_animated/dog.avif)
Delivering animated images with automatic format selection
You can also create animated images from videos together with automatic format selection (f_auto
). To deliver the asset as an animated image rather than a video, you have two options:
- Add the
animated
flag (fl_animated
) as well asf_auto
. - Add the
animated
option when specifying automatic format (f_auto:animated
).
Adding either of these options will deliver an animated image in a format that is supported by the browser.
For example, to deliver an animated image of the MP4 video named dog
using the optimal format for the user's browser:
![Animated images with f_auto Animated images with f_auto](https://res.cloudinary.com/demo/video/upload/c_scale,w_250/f_auto,fl_animated/dog.gif)
or