Ho un NSURL che contiene un video e voglio registrare un fotogramma di quel video dieci volte ogni secondo. E ho il codice che catturerà un'immagine del mio lettore, ma ho difficoltà a configurarlo per catturare 10 fotogrammi al secondo. Sto provando qualcosa del genere, ma sta restituendo lo stesso frame iniziale del video, il numero corretto di volte? Ecco cosa ho:iOS scatta più scatti dello schermo
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;
}
Ma invece di ottenere il fotogramma al momento attuale del video, ho appena ottenuto il frame iniziale?
Come posso ottenere il frame del video 10 volte al secondo?
Grazie per l'aiuto :)
La stessa domanda utilizzando Swift http://stackoverflow.com/questions/32286320/grab-frames-from-video-using-swift/32297251 – arpo