视频截帧功能可以从视频流中截取指定时刻的单帧画面,并按指定大小缩放成图片。
以下代码展示如何截取第 1000ms 的视频帧,并将截取后的图片下载到本地。
// 从STS服务获取的临时访问密钥和安全令牌(AccessKey、SecretKey、SecurityToken) TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey" securityToken:@"securityToken"]; TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"]; TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential]; TOSClient *client = [[TOSClient alloc] initWithConfiguration:config]; TOSGetObjectToFileInput *get = [TOSGetObjectToFileInput new]; get.tosBucket = @"bucket-name"; get.tosKey = @"video-name"; get.tosFilePath = @"your_local_file_path"; get.tosProcess = @"video/snapshot,t_1000"; TOSTask *task = [client getObjectToFile:get]; [task continueWithBlock:^id _Nullable(TOSTask * _Nonnull t) { if (!t.error) { NSLog(@"Get object to file success."); } else { NSLog(@"Get object to file failed, error: %@" ,t.error); } return nil; }];
关于视频截帧的详细介绍,请参见视频截帧。