gpt4 book ai didi

iphone - 如何从录制的视频中获取帧作为图像 -AVFoundation(图像作为缩略图)

转载 作者:行者123 更新时间:2023-11-28 18:37:22 25 4
gpt4 key购买 nike

我想从录制的视频中提取图像。我正在使用此代码 m 但没有结果,图像没有显示。

我正在使用下面的代码来完成这个任务

AVURLAsset* asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:videoPath] options:nil];
AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]];
[videoFrame setImage:image];

请帮忙编写一个代码用于从录制的视频中提取图像

最佳答案

试试这个

    NSURL *videoURl = [NSURL fileURLWithPath:videoPath];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURl options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generate.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 60);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *img = [[UIImage alloc] initWithCGImage:imgRef];
[videoFrame setImage:img];
[img release];

关于iphone - 如何从录制的视频中获取帧作为图像 -AVFoundation(图像作为缩略图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16313737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com