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).
The transformation count for animated images and videos converted to animated AVIF from other formats is based on the number of frames of the transformed file.
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:
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("cld_rubix.gif")
.resize(scale().height(200))
.animated(edit().loop())
.transcode(toAnimated().sampling(40))
.animated(edit().delay(200))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("cld_rubix.gif")
.resize(scale().height(200))
.animated(edit().loop())
.transcode(toAnimated().sampling(40))
.animated(edit().delay(200))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("cld_rubix.gif")
.resize(scale().height(200))
.animated(edit().loop())
.transcode(toAnimated().sampling(40))
.animated(edit().delay(200))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("cld_rubix.gif")
.resize(scale().height(200))
.animated(edit().loop())
.transcode(toAnimated().sampling(40))
.animated(edit().delay(200))
.setAssetType("video");
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:
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(200))
.animated(edit().loop(2))
.transcode(toAnimated().sampling("1.1s"))
.animated(edit().delay(200))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(200))
.animated(edit().loop(2))
.transcode(toAnimated().sampling("1.1s"))
.animated(edit().delay(200))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(200))
.animated(edit().loop(2))
.transcode(toAnimated().sampling("1.1s"))
.animated(edit().delay(200))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(200))
.animated(edit().loop(2))
.transcode(toAnimated().sampling("1.1s"))
.animated(edit().delay(200))
.setAssetType("video");
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:
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.webp")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.webp")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.webp")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.webp")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
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:
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(250))
.transcode(toAnimated("auto"))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(250))
.transcode(toAnimated("auto"))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(250))
.transcode(toAnimated("auto"))
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.gif")
.resize(scale().width(250))
.transcode(toAnimated("auto"))
.setAssetType("video");
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:
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.png")
.resize(scale().width(250))
.transcode(toAnimated())
.addFlag("apng")
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.png")
.resize(scale().width(250))
.transcode(toAnimated())
.addFlag("apng")
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.png")
.resize(scale().width(250))
.transcode(toAnimated())
.addFlag("apng")
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.png")
.resize(scale().width(250))
.transcode(toAnimated())
.addFlag("apng")
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.avif")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.avif")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.avif")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");
// This SDK requires imports from @cloudinary/url-gen. Learn more in the SDK docs.new CloudinaryImage("dog.avif")
.resize(scale().width(250))
.transcode(toAnimated())
.setAssetType("video");