próbuję przekonwertować cały film w sekwencji obrazów z szybkością 60fps, co oznacza 60 obrazów generowanych na sekundę wideo ...iOS AVFoundation - Konwersja wideo do zdjęć przy 60 fps
Aby tak robię, używam AVAssetImageGenerator i metoda generateCGImagesAsynchronouslyForTimes ...
Rzeczy idą całkiem dobrze z wyjątkiem, że mam poważne problemy z wydajnością regarging czas przetwarzania przetwarzania wsadowego (około 5 minut na 13 sekund wideo). ..
Ponadto powyżej rozmiaru CGSizeMake (512, 324) występują awarie. ..
Czy ktoś już miał doświadczenie z tego rodzaju przetwarzaniem i wie, jak zmniejszyć to wykonanie czasu, a także czy może wyodrębnić obrazy w wyższej rozdzielczości?
Poniżej znajduje się kod Jestem testowania ...
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];
Dziękując z góry,
j.
Występuje ten sam problem, z wyjątkiem przypadku, w którym próbuję wyciąć około 14 bardzo krótkich klipów wideo. Czy kiedykolwiek wymyśliłeś możliwe optymalizacje? – afrederick