You need to enable JavaScript to run this app.
导航

视频截帧图片持久化(iOS SDK)

最近更新时间2024.02.04 18:31:09

首次发布时间2023.11.03 16:08:04

TOS 支持将视频截帧后的图片保存到指定存储桶。

示例代码

以下代码展示如何截取第 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];

TOSGetObjectInput *get = [TOSGetObjectInput new];
get.tosBucket = @"bucket-name";
get.tosKey = @"video-name";
get.tosProcess = @"video/snapshot,t_1000";
get.tosProcessSaveAsBucket = @"target-bucket-name";
get.tosProcessSaveAsObject = @"target-image-name";
TOSTask *task = [client getObject:get];
[task continueWithBlock:^id _Nullable(TOSTask * _Nonnull t) {
    if (!task.error) {
        NSLog(@"Get object success.");
        // 获取转存结果
        TOSGetObjectOutput *out = t.result;
        NSLog(@"%@", [[NSString alloc] initWithData:out.tosContent encoding:NSUTF8StringEncoding]);
    } else {
        NSLog(@"Get object failed, error: %@" ,task.error);
    }
    return nil;
}];

相关文档

关于视频截帧图片持久化的详细介绍,请参见图片持久化