I have an NSURL that contains a video, and I want to record a frame of that video ten times every seconds. And I have code that will capture an image of my player, but I have trouble setting it up to take capture 10 frames per second. I am trying something like this, but it is returning the same initial frame of the video, the correct number of times? Here is what I have:
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;
}
But instead of getting the frame at the current time i of the video, I just get the initial frame?
How can I get the frame of the video 10 times a second?
Thanks for the help :)