Converting videos to animated images

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 and animated AVIFs are currently supported only in Chrome and Opera. 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 and WebP support 24-bit RGB color with an 8-bit alpha channel, compared to AVIF's 12-bit color depth and 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).

Tip
You can also deliver animated images as video files. For details, see Converting an animated GIF to video.

Delivering animated GIFs

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:

  1. 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:

    Ruby (cloudinary 1.x):
    Copy to clipboard
    cl_image_tag("cld_rubix.gif", :resource_type=>"video", :transformation=>[
      {:height=>200, :crop=>"scale"},
      {:effect=>"loop"},
      {:delay=>"200", :video_sampling=>"40"}
      ])
    PHP (cloudinary_php 2.x):
    Copy to clipboard
    (new ImageTag('cld_rubix.gif'))
      ->resize(Resize::scale()->height(200))
      ->animated(Animated::edit()->loop())
      ->transcode(Transcode::toAnimated()->sampling(40))
      ->animated(Animated::edit()->delay(200))
      ->assetType("video");
    PHP (cloudinary_php 1.x (legacy)):
    Copy to clipboard
    cl_image_tag("cld_rubix.gif", array("resource_type"=>"video", "transformation"=>array(
      array("height"=>200, "crop"=>"scale"),
      array("effect"=>"loop"),
      array("delay"=>"200", "video_sampling"=>"40")
      )))
    Python (cloudinary 1.x):
    Copy to clipboard
    CloudinaryVideo("cld_rubix.gif").image(transformation=[
      {'height': 200, 'crop': "scale"},
      {'effect': "loop"},
      {'delay': "200", 'video_sampling': "40"}
      ])
    Node.js (cloudinary 1.x):
    Copy to clipboard
    cloudinary.image("cld_rubix.gif", {resource_type: "video", transformation: [
      {height: 200, crop: "scale"},
      {effect: "loop"},
      {delay: "200", video_sampling: "40"}
      ]})
    Java (cloudinary 1.x):
    Copy to clipboard
    cloudinary.url().transformation(new Transformation()
      .height(200).crop("scale").chain()
      .effect("loop").chain()
      .delay("200").videoSampling("40")).resourceType("video").imageTag("cld_rubix.gif");
    JS (@cloudinary/url-gen 1.x):
    Copy to clipboard
    new CloudinaryImage("cld_rubix.gif")
      .resize(scale().height(200))
      .animated(edit().loop())
      .transcode(toAnimated().sampling(40))
      .animated(edit().delay(200))
      .setAssetType("video");
    JS (cloudinary-core 2.x (legacy)):
    Copy to clipboard
    cloudinary.videoTag('cld_rubix.gif', {transformation: [
      {height: 200, crop: "scale"},
      {effect: "loop"},
      {delay: "200", videoSampling: "40"}
      ]}).toHtml();
    jQuery (cloudinary-jquery 2.x):
    Copy to clipboard
    $.cloudinary.image("cld_rubix.gif", {resource_type: "video", transformation: [
      {height: 200, crop: "scale"},
      {effect: "loop"},
      {delay: "200", video_sampling: "40"}
      ]})
    React (@cloudinary/react 1.x):
    Copy to clipboard
    //React SDK transformations are created using @cloudinary/url-gen.
    new CloudinaryImage("cld_rubix.gif")
      .resize(scale().height(200))
      .animated(edit().loop())
      .transcode(toAnimated().sampling(40))
      .animated(edit().delay(200))
      .setAssetType("video");
    React (cloudinary-react 1.x):
    Copy to clipboard
    <Video publicId="cld_rubix.gif" resourceType="video">
      <Transformation height="200" crop="scale" />
      <Transformation effect="loop" />
      <Transformation delay="200" videoSampling="40" />
    </Video>
    Vue.js (cloudinary-vue 1.x):
    Copy to clipboard
    <cld-video public-id="cld_rubix.gif" resource-type="video">
      <cld-transformation height="200" crop="scale" />
      <cld-transformation effect="loop" />
      <cld-transformation delay="200" video-sampling="40" />
    </cld-video>
    Angular (@cloudinary/ng 1.x):
    Copy to clipboard
    //Angular SDK transformations are created using @cloudinary/url-gen.
    new CloudinaryImage("cld_rubix.gif")
      .resize(scale().height(200))
      .animated(edit().loop())
      .transcode(toAnimated().sampling(40))
      .animated(edit().delay(200))
      .setAssetType("video");
    Angular (@cloudinary/angular-5.x 1.x (legacy)):
    Copy to clipboard
    <cl-video public-id="cld_rubix.gif" resource-type="video">
      <cl-transformation height="200" crop="scale">
      </cl-transformation>
      <cl-transformation effect="loop">
      </cl-transformation>
      <cl-transformation delay="200" video-sampling="40">
      </cl-transformation>
    </cl-video>
    .NET (CloudinaryDotNet 1.x):
    Copy to clipboard
    cloudinary.Api.UrlVideoUp.Transform(new Transformation()
      .Height(200).Crop("scale").Chain()
      .Effect("loop").Chain()
      .Delay("200").VideoSampling("40")).BuildImageTag("cld_rubix.gif")
    iOS (cloudinary 3.x):
    Copy to clipboard
    cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
      .setHeight(200).setCrop("scale").chain()
      .setEffect("loop").chain()
      .setDelay("200").setVideoSampling("40")).generate("cld_rubix.gif")
    Android (cloudinary-android 1.x):
    Copy to clipboard
    MediaManager.get().url().transformation(new Transformation()
      .height(200).crop("scale").chain()
      .effect("loop").chain()
      .delay("200").videoSampling("40")).resourceType("video").generate("cld_rubix.gif");
    Kotlin (kotlin-url-gen 1.x):
    Copy to clipboard
    // This code example is not currently available.
    Animated GIF from dog.mp4, created from 40 frames and with a delay of 100 milliseconds

  2. 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:

    Ruby (cloudinary 1.x):
    Copy to clipboard
    cl_image_tag("dog.gif", :resource_type=>"video", :transformation=>[
      {:width=>200, :crop=>"scale"},
      {:effect=>"loop:2"},
      {:delay=>"200", :video_sampling=>"1.1s"}
      ])
    PHP (cloudinary_php 2.x):
    Copy to clipboard
    (new ImageTag('dog.gif'))
      ->resize(Resize::scale()->width(200))
      ->animated(Animated::edit()->loop(2))
      ->transcode(Transcode::toAnimated()->sampling("1.1s"))
      ->animated(Animated::edit()->delay(200))
      ->assetType("video");
    PHP (cloudinary_php 1.x (legacy)):
    Copy to clipboard
    cl_image_tag("dog.gif", array("resource_type"=>"video", "transformation"=>array(
      array("width"=>200, "crop"=>"scale"),
      array("effect"=>"loop:2"),
      array("delay"=>"200", "video_sampling"=>"1.1s")
      )))
    Python (cloudinary 1.x):
    Copy to clipboard
    CloudinaryVideo("dog.gif").image(transformation=[
      {'width': 200, 'crop': "scale"},
      {'effect': "loop:2"},
      {'delay': "200", 'video_sampling': "1.1s"}
      ])
    Node.js (cloudinary 1.x):
    Copy to clipboard
    cloudinary.image("dog.gif", {resource_type: "video", transformation: [
      {width: 200, crop: "scale"},
      {effect: "loop:2"},
      {delay: "200", video_sampling: "1.1s"}
      ]})
    Java (cloudinary 1.x):
    Copy to clipboard
    cloudinary.url().transformation(new Transformation()
      .width(200).crop("scale").chain()
      .effect("loop:2").chain()
      .delay("200").videoSampling("1.1s")).resourceType("video").imageTag("dog.gif");
    JS (@cloudinary/url-gen 1.x):
    Copy to clipboard
    new CloudinaryImage("dog.gif")
      .resize(scale().width(200))
      .animated(edit().loop(2))
      .transcode(toAnimated().sampling("1.1s"))
      .animated(edit().delay(200))
      .setAssetType("video");
    JS (cloudinary-core 2.x (legacy)):
    Copy to clipboard
    cloudinary.videoTag('dog.gif', {transformation: [
      {width: 200, crop: "scale"},
      {effect: "loop:2"},
      {delay: "200", videoSampling: "1.1s"}
      ]}).toHtml();
    jQuery (cloudinary-jquery 2.x):
    Copy to clipboard
    $.cloudinary.image("dog.gif", {resource_type: "video", transformation: [
      {width: 200, crop: "scale"},
      {effect: "loop:2"},
      {delay: "200", video_sampling: "1.1s"}
      ]})
    React (@cloudinary/react 1.x):
    Copy to clipboard
    //React SDK transformations are created using @cloudinary/url-gen.
    new CloudinaryImage("dog.gif")
      .resize(scale().width(200))
      .animated(edit().loop(2))
      .transcode(toAnimated().sampling("1.1s"))
      .animated(edit().delay(200))
      .setAssetType("video");
    React (cloudinary-react 1.x):
    Copy to clipboard
    <Video publicId="dog.gif" resourceType="video">
      <Transformation width="200" crop="scale" />
      <Transformation effect="loop:2" />
      <Transformation delay="200" videoSampling="1.1s" />
    </Video>
    Vue.js (cloudinary-vue 1.x):
    Copy to clipboard
    <cld-video public-id="dog.gif" resource-type="video">
      <cld-transformation width="200" crop="scale" />
      <cld-transformation effect="loop:2" />
      <cld-transformation delay="200" video-sampling="1.1s" />
    </cld-video>
    Angular (@cloudinary/ng 1.x):
    Copy to clipboard
    //Angular SDK transformations are created using @cloudinary/url-gen.
    new CloudinaryImage("dog.gif")
      .resize(scale().width(200))
      .animated(edit().loop(2))
      .transcode(toAnimated().sampling("1.1s"))
      .animated(edit().delay(200))
      .setAssetType("video");
    Angular (@cloudinary/angular-5.x 1.x (legacy)):
    Copy to clipboard
    <cl-video public-id="dog.gif" resource-type="video">
      <cl-transformation width="200" crop="scale">
      </cl-transformation>
      <cl-transformation effect="loop:2">
      </cl-transformation>
      <cl-transformation delay="200" video-sampling="1.1s">
      </cl-transformation>
    </cl-video>
    .NET (CloudinaryDotNet 1.x):
    Copy to clipboard
    cloudinary.Api.UrlVideoUp.Transform(new Transformation()
      .Width(200).Crop("scale").Chain()
      .Effect("loop:2").Chain()
      .Delay("200").VideoSampling("1.1s")).BuildImageTag("dog.gif")
    iOS (cloudinary 3.x):
    Copy to clipboard
    cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
      .setWidth(200).setCrop("scale").chain()
      .setEffect("loop:2").chain()
      .setDelay("200").setVideoSampling("1.1s")).generate("dog.gif")
    Android (cloudinary-android 1.x):
    Copy to clipboard
    MediaManager.get().url().transformation(new Transformation()
      .width(200).crop("scale").chain()
      .effect("loop:2").chain()
      .delay("200").videoSampling("1.1s")).resourceType("video").generate("dog.gif");
    Kotlin (kotlin-url-gen 1.x):
    Copy to clipboard
    // This code example is not currently available.
    Animated GIF from dog.mp4, created from a frame every 1.1 seconds and with a delay of 200 milliseconds

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:

Ruby (cloudinary 1.x):
Copy to clipboard
cl_image_tag("dog.webp", :resource_type=>"video", :transformation=>[
  {:width=>250, :crop=>"scale"},
  {:flags=>["animated", "awebp"]}
  ])
PHP (cloudinary_php 2.x):
Copy to clipboard
(new ImageTag('dog.webp'))
  ->resize(Resize::scale()->width(250))
  ->transcode(Transcode::toAnimated())
  ->assetType("video");
PHP (cloudinary_php 1.x (legacy)):
Copy to clipboard
cl_image_tag("dog.webp", array("resource_type"=>"video", "transformation"=>array(
  array("width"=>250, "crop"=>"scale"),
  array("flags"=>array("animated", "awebp"))
  )))
Python (cloudinary 1.x):
Copy to clipboard
CloudinaryVideo("dog.webp").image(transformation=[
  {'width': 250, 'crop': "scale"},
  {'flags': ["animated", "awebp"]}
  ])
Node.js (cloudinary 1.x):
Copy to clipboard
cloudinary.image("dog.webp", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: ["animated", "awebp"]}
  ]})
Java (cloudinary 1.x):
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated", "awebp")).resourceType("video").imageTag("dog.webp");
JS (@cloudinary/url-gen 1.x):
Copy to clipboard
new CloudinaryImage("dog.webp")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .setAssetType("video");
JS (cloudinary-core 2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('dog.webp', {transformation: [
  {width: 250, crop: "scale"},
  {flags: ["animated", "awebp"]}
  ]}).toHtml();
jQuery (cloudinary-jquery 2.x):
Copy to clipboard
$.cloudinary.image("dog.webp", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: ["animated", "awebp"]}
  ]})
React (@cloudinary/react 1.x):
Copy to clipboard
//React SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.webp")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .setAssetType("video");
React (cloudinary-react 1.x):
Copy to clipboard
<Video publicId="dog.webp" resourceType="video">
  <Transformation width="250" crop="scale" />
  <Transformation flags={["animated", "awebp"]} />
</Video>
Vue.js (cloudinary-vue 1.x):
Copy to clipboard
<cld-video public-id="dog.webp" resource-type="video">
  <cld-transformation width="250" crop="scale" />
  <cld-transformation flags={["animated", "awebp"]} />
</cld-video>
Angular (@cloudinary/ng 1.x):
Copy to clipboard
//Angular SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.webp")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .setAssetType("video");
Angular (@cloudinary/angular-5.x 1.x (legacy)):
Copy to clipboard
<cl-video public-id="dog.webp" resource-type="video">
  <cl-transformation width="250" crop="scale">
  </cl-transformation>
  <cl-transformation flags={{["animated", "awebp"]}}>
  </cl-transformation>
</cl-video>
.NET (CloudinaryDotNet 1.x):
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(250).Crop("scale").Chain()
  .Flags("animated", "awebp")).BuildImageTag("dog.webp")
iOS (cloudinary 3.x):
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(250).setCrop("scale").chain()
  .setFlags("animated", "awebp")).generate("dog.webp")
Android (cloudinary-android 1.x):
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated", "awebp")).resourceType("video").generate("dog.webp");
Kotlin (kotlin-url-gen 1.x):
Copy to clipboard
// This code example is not currently available.
Animated WebP created from the dog 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:

Ruby (cloudinary 1.x):
Copy to clipboard
cl_image_tag("dog.gif", :resource_type=>"video", :transformation=>[
  {:width=>250, :crop=>"scale"},
  {:flags=>"animated", :fetch_format=>:auto}
  ])
PHP (cloudinary_php 2.x):
Copy to clipboard
(new ImageTag('dog.gif'))
  ->resize(Resize::scale()->width(250))
  ->transcode(Transcode::toAnimated(
  AnimatedFormat::auto()))
  ->assetType("video");
PHP (cloudinary_php 1.x (legacy)):
Copy to clipboard
cl_image_tag("dog.gif", array("resource_type"=>"video", "transformation"=>array(
  array("width"=>250, "crop"=>"scale"),
  array("flags"=>"animated", "fetch_format"=>"auto")
  )))
Python (cloudinary 1.x):
Copy to clipboard
CloudinaryVideo("dog.gif").image(transformation=[
  {'width': 250, 'crop': "scale"},
  {'flags': "animated", 'fetch_format': "auto"}
  ])
Node.js (cloudinary 1.x):
Copy to clipboard
cloudinary.image("dog.gif", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: "animated", fetch_format: "auto"}
  ]})
Java (cloudinary 1.x):
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated").fetchFormat("auto")).resourceType("video").imageTag("dog.gif");
JS (@cloudinary/url-gen 1.x):
Copy to clipboard
new CloudinaryImage("dog.gif")
  .resize(scale().width(250))
  .transcode(toAnimated("auto"))
  .setAssetType("video");
JS (cloudinary-core 2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('dog.gif', {transformation: [
  {width: 250, crop: "scale"},
  {flags: "animated", fetchFormat: "auto"}
  ]}).toHtml();
jQuery (cloudinary-jquery 2.x):
Copy to clipboard
$.cloudinary.image("dog.gif", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: "animated", fetch_format: "auto"}
  ]})
React (@cloudinary/react 1.x):
Copy to clipboard
//React SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.gif")
  .resize(scale().width(250))
  .transcode(toAnimated("auto"))
  .setAssetType("video");
React (cloudinary-react 1.x):
Copy to clipboard
<Video publicId="dog.gif" resourceType="video">
  <Transformation width="250" crop="scale" />
  <Transformation flags="animated" fetchFormat="auto" />
</Video>
Vue.js (cloudinary-vue 1.x):
Copy to clipboard
<cld-video public-id="dog.gif" resource-type="video">
  <cld-transformation width="250" crop="scale" />
  <cld-transformation flags="animated" fetch-format="auto" />
</cld-video>
Angular (@cloudinary/ng 1.x):
Copy to clipboard
//Angular SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.gif")
  .resize(scale().width(250))
  .transcode(toAnimated("auto"))
  .setAssetType("video");
Angular (@cloudinary/angular-5.x 1.x (legacy)):
Copy to clipboard
<cl-video public-id="dog.gif" resource-type="video">
  <cl-transformation width="250" crop="scale">
  </cl-transformation>
  <cl-transformation flags="animated" fetch-format="auto">
  </cl-transformation>
</cl-video>
.NET (CloudinaryDotNet 1.x):
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(250).Crop("scale").Chain()
  .Flags("animated").FetchFormat("auto")).BuildImageTag("dog.gif")
iOS (cloudinary 3.x):
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(250).setCrop("scale").chain()
  .setFlags("animated").setFetchFormat("auto")).generate("dog.gif")
Android (cloudinary-android 1.x):
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated").fetchFormat("auto")).resourceType("video").generate("dog.gif");
Kotlin (kotlin-url-gen 1.x):
Copy to clipboard
// This code example is not currently available.
Animated images with f_auto

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:

Ruby (cloudinary 1.x):
Copy to clipboard
cl_image_tag("dog.png", :resource_type=>"video", :transformation=>[
  {:width=>250, :crop=>"scale"},
  {:flags=>["animated", "apng"]}
  ])
PHP (cloudinary_php 2.x):
Copy to clipboard
(new ImageTag('dog.png'))
  ->resize(Resize::scale()->width(250))
  ->transcode(Transcode::toAnimated())
  ->addFlag("apng")
  ->assetType("video");
PHP (cloudinary_php 1.x (legacy)):
Copy to clipboard
cl_image_tag("dog.png", array("resource_type"=>"video", "transformation"=>array(
  array("width"=>250, "crop"=>"scale"),
  array("flags"=>array("animated", "apng"))
  )))
Python (cloudinary 1.x):
Copy to clipboard
CloudinaryVideo("dog.png").image(transformation=[
  {'width': 250, 'crop': "scale"},
  {'flags': ["animated", "apng"]}
  ])
Node.js (cloudinary 1.x):
Copy to clipboard
cloudinary.image("dog.png", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: ["animated", "apng"]}
  ]})
Java (cloudinary 1.x):
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated", "apng")).resourceType("video").imageTag("dog.png");
JS (@cloudinary/url-gen 1.x):
Copy to clipboard
new CloudinaryImage("dog.png")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .addFlag("apng")
  .setAssetType("video");
JS (cloudinary-core 2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('dog.png', {transformation: [
  {width: 250, crop: "scale"},
  {flags: ["animated", "apng"]}
  ]}).toHtml();
jQuery (cloudinary-jquery 2.x):
Copy to clipboard
$.cloudinary.image("dog.png", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: ["animated", "apng"]}
  ]})
React (@cloudinary/react 1.x):
Copy to clipboard
//React SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.png")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .addFlag("apng")
  .setAssetType("video");
React (cloudinary-react 1.x):
Copy to clipboard
<Video publicId="dog.png" resourceType="video">
  <Transformation width="250" crop="scale" />
  <Transformation flags={["animated", "apng"]} />
</Video>
Vue.js (cloudinary-vue 1.x):
Copy to clipboard
<cld-video public-id="dog.png" resource-type="video">
  <cld-transformation width="250" crop="scale" />
  <cld-transformation flags={["animated", "apng"]} />
</cld-video>
Angular (@cloudinary/ng 1.x):
Copy to clipboard
//Angular SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.png")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .addFlag("apng")
  .setAssetType("video");
Angular (@cloudinary/angular-5.x 1.x (legacy)):
Copy to clipboard
<cl-video public-id="dog.png" resource-type="video">
  <cl-transformation width="250" crop="scale">
  </cl-transformation>
  <cl-transformation flags={{["animated", "apng"]}}>
  </cl-transformation>
</cl-video>
.NET (CloudinaryDotNet 1.x):
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(250).Crop("scale").Chain()
  .Flags("animated", "apng")).BuildImageTag("dog.png")
iOS (cloudinary 3.x):
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(250).setCrop("scale").chain()
  .setFlags("animated", "apng")).generate("dog.png")
Android (cloudinary-android 1.x):
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated", "apng")).resourceType("video").generate("dog.png");
Kotlin (kotlin-url-gen 1.x):
Copy to clipboard
// This code example is not currently available.
Animated PMG created from the dog video

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:

Ruby (cloudinary 1.x):
Copy to clipboard
cl_image_tag("dog.avif", :resource_type=>"video", :transformation=>[
  {:width=>250, :crop=>"scale"},
  {:flags=>"animated"}
  ])
PHP (cloudinary_php 2.x):
Copy to clipboard
(new ImageTag('dog.avif'))
  ->resize(Resize::scale()->width(250))
  ->transcode(Transcode::toAnimated())
  ->assetType("video");
PHP (cloudinary_php 1.x (legacy)):
Copy to clipboard
cl_image_tag("dog.avif", array("resource_type"=>"video", "transformation"=>array(
  array("width"=>250, "crop"=>"scale"),
  array("flags"=>"animated")
  )))
Python (cloudinary 1.x):
Copy to clipboard
CloudinaryVideo("dog.avif").image(transformation=[
  {'width': 250, 'crop': "scale"},
  {'flags': "animated"}
  ])
Node.js (cloudinary 1.x):
Copy to clipboard
cloudinary.image("dog.avif", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: "animated"}
  ]})
Java (cloudinary 1.x):
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated")).resourceType("video").imageTag("dog.avif");
JS (@cloudinary/url-gen 1.x):
Copy to clipboard
new CloudinaryImage("dog.avif")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .setAssetType("video");
JS (cloudinary-core 2.x (legacy)):
Copy to clipboard
cloudinary.videoTag('dog.avif', {transformation: [
  {width: 250, crop: "scale"},
  {flags: "animated"}
  ]}).toHtml();
jQuery (cloudinary-jquery 2.x):
Copy to clipboard
$.cloudinary.image("dog.avif", {resource_type: "video", transformation: [
  {width: 250, crop: "scale"},
  {flags: "animated"}
  ]})
React (@cloudinary/react 1.x):
Copy to clipboard
//React SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.avif")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .setAssetType("video");
React (cloudinary-react 1.x):
Copy to clipboard
<Video publicId="dog.avif" resourceType="video">
  <Transformation width="250" crop="scale" />
  <Transformation flags="animated" />
</Video>
Vue.js (cloudinary-vue 1.x):
Copy to clipboard
<cld-video public-id="dog.avif" resource-type="video">
  <cld-transformation width="250" crop="scale" />
  <cld-transformation flags="animated" />
</cld-video>
Angular (@cloudinary/ng 1.x):
Copy to clipboard
//Angular SDK transformations are created using @cloudinary/url-gen.
new CloudinaryImage("dog.avif")
  .resize(scale().width(250))
  .transcode(toAnimated())
  .setAssetType("video");
Angular (@cloudinary/angular-5.x 1.x (legacy)):
Copy to clipboard
<cl-video public-id="dog.avif" resource-type="video">
  <cl-transformation width="250" crop="scale">
  </cl-transformation>
  <cl-transformation flags="animated">
  </cl-transformation>
</cl-video>
.NET (CloudinaryDotNet 1.x):
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation()
  .Width(250).Crop("scale").Chain()
  .Flags("animated")).BuildImageTag("dog.avif")
iOS (cloudinary 3.x):
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation()
  .setWidth(250).setCrop("scale").chain()
  .setFlags("animated")).generate("dog.avif")
Android (cloudinary-android 1.x):
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .width(250).crop("scale").chain()
  .flags("animated")).resourceType("video").generate("dog.avif");
Kotlin (kotlin-url-gen 1.x):
Copy to clipboard
// This code example is not currently available.
Animated AVIF created from the dog video

✔️ Feedback sent!

Rate this page: