You can convert videos to animated images in formats such as GIF and WebP.
Feature description
Video-to-animated-image conversion transforms video files into dynamic image formats, such as GIF or WebP, enabling easy sharing and embedding on web pages and social media.

Use cases
Social media clips: Extract short moments from video and share them as animated images on social platforms.
Tutorials and demos: Capture step-by-step software operations as looping animated images that readers can follow without playing a video.
Stickers and reactions: Turn video moments into animated stickers for messaging apps.
Event highlights: Clip key moments from live streams, competitions, or presentations and share them instantly.
How to use
Prerequisites
In Object Storage Service (OSS), create a bucket and upload the files that you want to process to the bucket.
Create and attach an IMM project. You can attach the project in the OSS console or by calling an API. The IMM project must be in the same region as the bucket.
Permissions for the operations of authorized users have been granted.
Convert videos to animated images
You can convert videos to animated images asynchronously only using the software development kits (SDKs) for Java, Python, or Go.
Java
The Java SDK V3.17.4 or later is required.
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.AsyncProcessObjectRequest;
import com.aliyun.oss.model.AsyncProcessObjectResult;
import com.aliyuncs.exceptions.ClientException;
import java.util.Base64;
public class Demo {
public static void main(String[] args) throws ClientException {
// Set endpoint to the endpoint of the region where the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region information that corresponds to the endpoint, for example, cn-hangzhou.
String region = "cn-hangzhou";
// Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name.
String bucketName = "examplebucket";
// Specify the name of the output animated GIF file.
String targetKey = "dest.gif";
// Specify the name of the source video file.
String sourceKey = "src.mp4";
// Create an OSSClient instance.
// When the OSSClient instance is no longer used, call the shutdown method to release the resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Build a string for the video processing style and the parameters for converting the video to an animated image.
String style = String.format("video/animation,f_gif,w_100,h_100,inter_1000");
// Build the asynchronous processing instruction.
String bucketEncoded = Base64.getUrlEncoder().withoutPadding().encodeToString(bucketName.getBytes());
String targetEncoded = Base64.getUrlEncoder().withoutPadding().encodeToString(targetKey.getBytes());
String process = String.format("%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0", style, bucketEncoded, targetEncoded);
// Create an AsyncProcessObjectRequest object.
AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, sourceKey, process);
// Execute the asynchronous processing task.
AsyncProcessObjectResult response = ossClient.asyncProcessObject(request);
System.out.println("EventId: " + response.getEventId());
System.out.println("RequestId: " + response.getRequestId());
System.out.println("TaskId: " + response.getTaskId());
} finally {
// Shut down the OSSClient.
ossClient.shutdown();
}
}
}Python
The Python SDK V2.18.4 or later is required.
# -*- coding: utf-8 -*-
import base64
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
def main():
# Obtain temporary access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Set endpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the general-purpose Alibaba Cloud region ID, for example, cn-hangzhou.
region = 'cn-hangzhou'
# Specify the bucket name, for example, examplebucket.
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# Specify the name of the source video file.
source_key = 'src.mp4'
# Specify the name of the output animated GIF file.
target_key = 'example.gif'
# Define the parameters for converting the video to an animated GIF, including the GIF width, height, and frame interval.
animation_style = 'video/animation,f_gif,w_100,h_100,inter_1000'
# Build the processing instruction, including the save path and the Base64-encoded bucket name and object file name.
bucket_name_encoded = base64.urlsafe_b64encode('examplebucket'.encode()).decode().rstrip('=')
target_key_encoded = base64.urlsafe_b64encode(target_key.encode()).decode().rstrip('=')
process = f"{animation_style}|sys/saveas,b_{bucket_name_encoded},o_{target_key_encoded}/notify,topic_QXVkaW9Db252ZXJ0"
try:
# Execute the asynchronous processing task.
result = bucket.async_process_object(source_key, process)
print(f"EventId: {result.event_id}")
print(f"RequestId: {result.request_id}")
print(f"TaskId: {result.task_id}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()Go
The Go SDK V3.0.2 or later is required.
package main
import (
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"log"
)
func main() {
// Obtain temporary access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
// Set yourEndpoint to the endpoint of the bucket. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual endpoint.
// Set yourRegion to the general-purpose Alibaba Cloud region ID, for example, cn-hangzhou.
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the bucket name, for example, examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the name of the source video file.
sourceKey := "src.mp4"
// Specify the name of the output animated GIF file.
targetKey := "destexample.gif"
// Define the parameters for converting the video to an animated GIF, including the GIF width, height, and frame interval.
animationStyle := "video/animation,f_gif,w_100,h_100,inter_1000"
// Build the processing instruction, including the save path and the Base64-encoded bucket name and object file name.
bucketNameEncoded := base64.URLEncoding.EncodeToString([]byte(bucketName))
targetKeyEncoded := base64.URLEncoding.EncodeToString([]byte(targetKey))
process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", animationStyle, bucketNameEncoded, targetKeyEncoded)
// Execute the asynchronous processing task.
result, err := bucket.AsyncProcessObject(sourceKey, process)
if err != nil {
log.Fatalf("Failed to async process object: %s", err)
}
fmt.Printf("EventId: %s\n", result.EventId)
fmt.Printf("RequestId: %s\n", result.RequestId)
fmt.Printf("TaskId: %s\n", result.TaskId)
}Parameter description
Action: video/animation
The following table describes the parameters.
Parameter | Type | Required | Description |
ss | int | No | The start time of the video-to-animated-image conversion. Unit: milliseconds. Valid values:
|
f | string | Yes | The output format of the animated image. Valid values:
|
num | int | No | The number of frames in the animated image. By default, the number of frames is not limited, and frames are extracted until the end of the video. Important If the video is not long enough, the actual number of extracted frames is less than the specified value. |
inter | int | No | The interval at which frames are extracted for the animated image. Unit: milliseconds. By default, all video frames are extracted. Note If this value is less than the source video keyframe interval (the reciprocal of the frame rate), frames are extracted at the source video keyframe interval. |
fps | float | No | The frame rate of the animated image. Default value: the reciprocal of inter. The value must be in the range of [0, 240]. Note This parameter controls the playback speed of the animated image. If you use the default value, the playback speed is the same as the source video. A value greater than the default value speeds up playback. A value smaller than the default value slows down playback. |
w | int | No | The width of the output animated image. Unit: px. The value must be in the range of [32, 4096]. Default value: the width of the source video. |
h | int | No | The height of the output animated image. Unit: px. The value must be in the range of [32, 4096]. Default value: the height of the source video. |
scaletype | string | No | The scaling method. Valid values:
|
When you convert a video to an animated image, the sys/saveas and notify parameters are used. For more information, see Save As and Notifications.
Related APIs
Convert a video to an animated image by extracting one frame per second
Source video file: example.mkv
Processing parameters:
Format: gif (
f_gif)Output image resolution: 100 px × 100 px (
w_100,h_100)Frame extraction interval: 1 s (
inter_1000)
Storage path: oss://outbucket/outobjprefix.{autoext}
Bucket: outbucket (Base64-encoded:
b_b3V0YnVja2V0)Object: outobjprefix.{autoext} (Base64-encoded:
o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQ)
Notification parameters:
Notification method: Send MNS messages
Notification subject: AudioConvert (Base64-encoded:
topic_QXVkaW9Db252ZXJ0)
Processing Example
// Convert the example.mkv file to an animated image.
POST /example.mkv?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
x-oss-async-process=video/animation,f_gif,w_100,h_100,inter_1000|sys/saveas,b_b3V0YnVja2V0,o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQ/notify,topic_QXVkaW9Db252ZXJ0Convert a video to an animated image by extracting one frame every 0.5 seconds, starting from the 5th second
Source video file: example.mkv
Processing parameters:
Format: webp (
f_webp)Output image resolution: 25% of the source video's width and height (
pw_25, ph_25)Frame extraction interval: 0.5 s (
inter_500)
Storage path: oss://outbucket/outobjprefix.{autoext}
Bucket: outbucket (Base64-encoded:
b_b3V0YnVja2V0)Object: outobjprefix.{autoext} (Base64-encoded:
o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQ)
Notification parameters:
Notification method: Send MNS messages
Notification subject: AudioConvert (Base64-encoded:
topic_QXVkaW9Db252ZXJ0)
Processing Example
// Convert the example.mkv file to an animated image.
POST /example.mkv?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
x-oss-async-process=video/animation,ss_5000,f_webp,pw_25,ph_25,fps_25,inter_500|sys/saveas,b_b3V0YnVja2V0,o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQ/notify,topic_QXVkaW9Db252ZXJ0Billing
When you convert a video to an animated image, IMM is called. This generates the following billable items for OSS and IMM:
OSS side: For detailed pricing, see OSS Pricing
API
Billable item
Description
GetObject
GET requests
Request fees are calculated based on the number of successful requests.
Outbound Internet Traffic Fees
If you call the GetObject operation using a public endpoint (for example, oss-cn-hangzhou.aliyuncs.com) or an acceleration endpoint (for example, oss-accelerate.aliyuncs.com), you are charged for outbound traffic over the internet. Fees are calculated based on the data size.
Volume of retrieved Infrequent Access (IA) data
If the retrieved data is IA data, you are charged for the volume of retrieved IA data. Fees are calculated based on the volume of retrieved data.
Volume of data retrieved from Archive objects using real-time access
If you read an Archive object and real-time access of Archive objects is enabled for the bucket, you are charged for the volume of data retrieved from the Archive object. Fees are calculated based on the size of the retrieved data.
Transfer acceleration
If you enable transfer acceleration and use an acceleration endpoint to access your bucket, you are charged for transfer acceleration. Fees are calculated based on the data size.
PutObject
PUT requests
Request fees are calculated based on the number of successful requests.
Storage fees
Storage fees are charged based on the storage class, size, and duration of an object.
HeadObject
GET requests
Request fees are calculated based on the number of successful requests.
IMM: For more information about pricing, see IMM billable items
ImportantStarting at 11:00 UTC+8 on July 28, 2025, the IMM Video-to-animated-image conversion service will upgrade from the free tier to a pay-as-you-go billing model. The specific billable item is MediaAnimation. For more information, see IMM Billing Adjustment Notice.
API
Billable item
Description
CreateMediaConvertTask
MediaAnimation
The fee for video-to-animated-image conversion is calculated based on the number of frames in the output animated image.
Notes
Video-to-animated-image conversion supports only asynchronous processing (x-oss-async-process).
-
Anonymous access will be denied.