que estoy tratando de convertir un video completo en una secuencia de imágenes a una velocidad de 60 fotogramas por segundo, lo que significa 60 imágenes generadas por segundo de vídeo ...iOS AVFoundation - Conversión de vídeo en imágenes a 60 fps
Para hacerlo, estoy haciendo uso de AVAssetImageGenerator y el método generateCGImagesAsynchronouslyForTimes ...
Las cosas van bastante bien, excepto que estoy teniendo problemas graves de rendimiento con respecto al tiempo de ejecución del procesamiento por lotes (aproximadamente 5 minutos para 13 segundos de video). ..
Además, por encima del siguiente tamaño CGSizeMake (512, 324), experimento bloqueos. ..
¿Alguien ya tiene experiencia con este tipo de procesamiento y sabe cómo reducir esta ejecución de tiempo así como también poder extraer las imágenes a una resolución más alta?
A continuación está el código que estoy probando ...
NSURL *movieURL = [NSURL fileURLWithPath:getCaptureMoviePath()];
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:movieURL options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
generator.requestedTimeToleranceAfter=kCMTimeZero;
generator.requestedTimeToleranceBefore=kCMTimeZero;
NSMutableArray *thumbTimes=[NSMutableArray arrayWithCapacity:asset.duration.value];
for(int t=0;t < asset.duration.value;t=t+2) {
CMTime thumbTime = CMTimeMake(t, asset.duration.timescale);
NSLog(@"Time Scale : %d ", asset.duration.timescale);
NSValue *v=[NSValue valueWithCMTime:thumbTime];
[thumbTimes addObject:v];
}
NSLog(@"thumbTimes array contains %d objects : ", [thumbTimes count]);
[asset release];
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error) {
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
} else {
NSLog(@"actual time: %lld/%d (requested: %lld/%d)",actualTime.value,actualTime.timescale,requestedTime.value,requestedTime.timescale);
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyyMMdd-HHmmss"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filename = [NSString stringWithFormat:@"%@.png", [formatter stringFromDate:[NSDate date]]];
NSString *filepath = [documentsDirectory stringByAppendingPathComponent:filename];
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:filepath];
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(destination, im, nil);
if (!CGImageDestinationFinalize(destination)) {
NSLog(@"Failed to write image to %@", filepath);
}
CFRelease(destination);
}
//[generator release];
};
CGSize maxSize = CGSizeMake(512, 324);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:thumbTimes completionHandler:handler];
Agradeciendo de antemano,
j.
Tengo el mismo problema, excepto en mi caso, estoy tratando de cortar aproximadamente 14 clips de video muy cortos. ¿Alguna vez descubrió posibles optimizaciones? – afrederick