我有一個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