You can use the video-to-animated-image conversion feature to convert videos into animated images in formats such as GIF and WebP.
Overview
Video-to-animated-image conversion transforms video files into animated image formats, such as GIF or WebP, making them easy to share and embed on websites and social media platforms.

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
-
The Intelligent Media Management (IMM) service is activated.
-
A bucket is created in OSS, and the files to be processed are uploaded to it.
-
An IMM Project is created and attached. You can attach it by using the OSS console or by calling an API. The IMM Project must be in the same region as the bucket.
-
The user is granted the required permissions for the operations.
Convert a video to an animated image
You can convert a video to an animated image only by using asynchronous processing with the OSS SDK for Java, Python, or Go.
Java
OSS SDK for Java 3.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 {
// The endpoint of the region in which the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// The region 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 configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// The bucket name.
String bucketName = "examplebucket";
// The name of the destination animated GIF file.
String targetKey = "dest.gif";
// The name of the source video file.
String sourceKey = "src.mp4";
// Create an OSSClient instance.
// When the OSSClient instance is no longer needed, call the shutdown method to release its 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 style string that contains the parameters for video-to-animated-image conversion.
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 instance.
ossClient.shutdown();
}
}
}
Python
OSS SDK for Python 2.18.4 or later is required.
# -*- coding: utf-8 -*-
import base64
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
def main():
# 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 configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# The endpoint of the region in which 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'
# The region ID, for example, cn-hangzhou.
region = 'cn-hangzhou'
# The bucket name, for example, examplebucket.
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# The name of the source video file.
source_key = 'src.mp4'
# The name of the destination animated GIF file.
target_key = 'example.gif'
# Define the parameters for converting the video to an animated GIF, such as 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 target object 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
OSS SDK for Go 3.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 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 configured.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
// Specify the endpoint of the bucket. For example, for a bucket in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual endpoint.
// Specify the 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)
}
// The bucket name, for example, examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// The name of the source video file.
sourceKey := "src.mp4"
// The name of the destination animated GIF file.
targetKey := "destexample.gif"
// Define the parameters for converting the video to an animated GIF, such as 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 target object 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)
}
Parameters
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, in milliseconds. Valid values:
|
|
f |
string |
Yes |
The output format of the animated image. Valid values:
|
|
num |
int |
No |
The number of frames to extract for the animated image. By default, frames are extracted until the end of the video. Important
If the video is not long enough to extract the specified number of frames, the actual number of extracted frames is less than the specified value. |
|
inter |
int |
No |
The frame extraction interval for the animated image, in milliseconds. By default, all video frames are extracted. Note
If the value of this parameter is less than the frame interval of the source video (the reciprocal of the frame rate), frames are extracted at the source video's frame interval. |
|
fps |
float |
No |
The frame rate of the animated image. The default value is the reciprocal of inter. Valid values: [0, 240]. Note
This parameter controls the playback speed of the animated image. The default value matches the source video's speed. A higher value speeds up playback, while a lower value slows it down. |
|
w |
int |
No |
The width of the output animated image, in pixels. Valid values: [32, 4096]. By default, the width is the same as the source video's width. |
|
h |
int |
No |
The height of the output animated image, in pixels. Valid values: [32, 4096]. By default, the height is the same as the source video's height. |
|
scaletype |
string |
No |
The resizing mode. Valid values:
|
The video-to-animated-image conversion process uses the sys/saveas and notify parameters. For more information, see Save as and Message notification.
Request examples
Extract one frame per second
Source video file: example.mkv
Processing parameters:
-
Output format: gif (
f_gif) -
Output image resolution: 100 px × 100 px (
w_100,h_100) -
Frame extraction interval: 1 second (
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 an MNS message
-
Notification topic: AudioConvert (Base64-encoded:
topic_QXVkaW9Db252ZXJ0)
Sample request
// Convert the example.mkv file into 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_QXVkaW9Db252ZXJ0
Extract frames from a specific start time
Source video file: example.mkv
Processing parameters:
-
Output format: webp (
f_webp) -
Output image resolution: 25% of the source video's width and height (
pw_25, ph_25) -
Frame extraction interval: 0.5s (
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 an MNS message
-
Notification topic: AudioConvert (Base64-encoded:
topic_QXVkaW9Db252ZXJ0)
Sample request
// Convert the example.mkv file into 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_QXVkaW9Db252ZXJ0
Billing
Video-to-animated-image conversion incurs fees from both OSS and IMM. The billable items include:
-
OSS: For more information about pricing, see OSS Pricing.
API
Billing item
Description
GetObject
GET requests
Request fees are calculated based on the number of successful requests.
Outbound traffic over the internet
If you call the GetObject operation by using a public endpoint (for example, oss-cn-hangzhou.aliyuncs.com) or a transfer acceleration endpoint (for example, oss-accelerate.aliyuncs.com), you are charged for outbound traffic over the internet based on the data volume.
Data retrieval from Infrequent Access (IA) storage
If you retrieve Infrequent Access (IA) objects, you are charged data retrieval fees based on the amount of retrieved data.
Data retrieval for archive direct read
If you read Archive objects from a bucket for which archive direct read is enabled, you are charged data retrieval fees based on the amount of retrieved data.
Transfer acceleration
If you enable transfer acceleration and use a transfer acceleration endpoint to access your bucket, you are charged transfer acceleration fees based on the data volume.
PutObject
PUT requests
Request fees are calculated based on the number of successful requests.
Storage fees
You are charged storage fees based on the storage class, size, and storage 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 billing items.
ImportantStarting from 11:00 (UTC+8) on July 28, 2025, the IMM video-to-animated-image conversion feature will be upgraded from a free to a paid service. The billable item is MediaAnimation. For more information, see the IMM billing adjustment announcement.
API
Billing item
Description
CreateMediaConvertTask
MediaAnimation
Fees for video-to-animated-image conversion are calculated based on the number of frames in the output animated image.
Usage notes
-
Video-to-animated-image conversion supports only asynchronous processing (by using the x-oss-async-process method).
-
Anonymous access will be denied.