我想从录制的视频中提取图像。我正在使用此代码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/