我有一个NSURL包含一个视频,我想记录该视频的帧每秒十次。我的代码能够捕捉到我的播放器的图像,但我无法将其设置为每秒捕捉10帧。我正在尝试这样的事情,但是它会返回视频的相同初始帧,正确的次数?这里是我有什么:iOS采取多个屏幕截图
AVAsset *asset = [AVAsset assetWithURL:videoUrl];
CMTime vidLength = asset.duration;
float seconds = CMTimeGetSeconds(vidLength);
int frameCount = 0;
for (float i = 0; i < seconds;) {
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
CMTime time = CMTimeMake(i, 10);
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
NSString* filename = [NSString stringWithFormat:@"Documents/frame_%d.png", frameCount];
NSString* pngPath = [NSHomeDirectory() stringByAppendingPathComponent:filename];
[UIImagePNGRepresentation(thumbnail) writeToFile: pngPath atomically: YES];
frameCount++;
i = i + 0.1;
}
但是,而不是获得当前时间我的视频帧,我只是得到初始帧?
我该如何获得每秒10次的视频帧?
感谢您的帮助:)
使用斯威夫特 同样的问题http://stackoverflow.com/questions/32286320/grab-frames-from-video-using-swift/32297251 – arpo 2015-08-30 14:13:39