You can upload videos to an Object Storage Service (OSS) bucket and use the video snapshot feature to extract video thumbnails, keyframes, or specific frames from the videos.
Usage notes
When you capture snapshots from videos, you are charged based on the number of captured snapshots. For more information, see Data processing fees.
OSS can capture snapshots from videos only in the H.264 and H.265 formats.
By default, OSS does not automatically store captured snapshots. You need to manually download captured snapshots to your local storage devices.
Parameters
Category: video
Action: snapshot
Parameter | Description | Valid value |
Parameter | Description | Valid value |
t | The point in time at which you want to capture the snapshot. If the value exceeds the length of the video, the last frame is returned. Note If you want to capture a video thumbnail, set t to 0. | [0, video duration] Unit: milliseconds |
w | The width of the snapshot to capture. If this parameter is set to 0, the width of the captured snapshot is calculated based on the proportion of the height of the captured snapshot to the video height. | [0, video width] Unit: pixel |
h | The height of the snapshot to capture. If this parameter is set to 0, the height of the captured snapshot is calculated based on the proportion of the width of the captured snapshot to the video width. If both w and h are set to 0, the snapshot width and height are the same as the video width and height. | [0, video height] Unit: pixel |
m | The mode used to capture the snapshot. If this parameter is not specified, the snapshot is captured in the default mode. In other words, the snapshot at the specified point in time of the video is captured. If this parameter is set to fast, the most recent keyframe before the specified point in time is captured. | fast |
f | The format of the snapshot to return. | jpg and png |
ar | The mode that you want to use to automatically rotate the captured snapshot. | auto: specifies that the captured snapshot is automatically rotated based on the video information. h: specifies that the captured snapshot is automatically rotated based on the mode in which the height is greater than the width. w: specifies that the captured snapshot is automatically rotated based on the mode in which the width is greater than the height.
|
Generate a signed URL to capture a video snapshot
You can use OSS SDKs to generate a signed URL to capture a video snapshot. The following sample code provides an example on how to use OSS SDK for Java to generate a signed URL to capture a video snapshot:
String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
String objectName = "examplefolder/videotest.mp4";
OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
String style = "video/snapshot,t_17000,f_jpg,w_800,h_600";
Date expiration = new Date(new Date().getTime() + 1000 * 60 * 10 );
GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET);
req.setExpiration(expiration);
req.setProcess(style);
URL signedUrl = ossClient.generatePresignedUrl(req);
System.out.println(signedUrl);
ossClient.shutdown();
The method used to generate signed URLs to capture video snapshots is similar to that used to generate signed URLs to process images by using Image Processing (IMG). To use the following OSS SDKs to generate a signed URL to capture a video snapshot, replace the IMG operations in the code with the snapshot operation.
FAQ
Can I process a video object whose ACL is private by directly adding parameters to the URL of the object?
No, you cannot. If the ACL of the video object that you want to process is private, you can use OSS SDKs to add video processing operations to the signed URL of the object. You cannot process a video object whose ACL is private by directly adding parameters to the object URL.
How do I check the width and height of a video object that is stored in OSS?
You can use the video information extraction feature to obtain the width and height of a video.
Why is a captured video snapshot distorted?
The video from which you capture the snapshot uses the BT.2020 color gamut. The video snapshot feature does not support videos that use the BT.2020 color gamut.