1
iPadビデオでAVFoundationフレームワークを使用してビデオを録画しています。ビデオの録画が完了したら、AVFoundation.Butを使用してサムネイル画像を作成します。サムネイルの間の時間遅延が正しく作成されていません.Clearlyそれはいくつかの遅延を取っています。それを避けるために、または少なくとも私は以前のビデオのサムネイルが完全に作成されたことを知ることができます。その期間のユーザーですか?サムネイルを作成するためにAVFoundationフレームワークが遅くなります
私はこの問題を解決する手掛かりがありませんのでお手伝いください。
//delegate method which gets called when recording ends.
//Here I create the thumb and store it in self.thumb
-(void)recorder:(AVCamRecorder *)recorder recordingDidFinishToOutputFileURL:(NSURL *)outputFileURL error:(NSError *)error
{
self.thumb=nil;
AVURLAsset *asset=[[AVURLAsset alloc] initWithURL:outputFileURL options:nil];
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;
[asset release];
CMTime thumbTime = CMTimeMakeWithSeconds(0,1);
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
if (result != AVAssetImageGeneratorSucceeded) {
NSLog(@"couldn't generate thumbnail, error:%@", error);
}
self.thumb=[UIImage imageWithCGImage:im];
[generator release];
};
CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
[[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
}
if ([[self delegate] respondsToSelector:@selector(captureManagerRecordingFinished:)]) {
[[self delegate] captureManagerRecordingFinished:self];
}
}
[self copyFileToDocuments:outputFileURL];
}
//Save video and thumbnail to documents
- (void) copyFileToDocuments:(NSURL *)fileURL
{
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd_HH-mm-ss"];
NSString *destinationPath = [documentsDirectory stringByAppendingFormat:@"/output_%@.mov", [dateFormatter stringFromDate:[NSDate date]]];
[dateFormatter release];
NSError *error;
if (![[NSFileManager defaultManager] copyItemAtURL:fileURL toURL:[NSURL fileURLWithPath:destinationPath] error:&error]) {
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
else
{
destinationPath=[[destinationPath lastPathComponent]stringByDeletingPathExtension];
[self saveImage:self.thumb withName:destinationPath];
}
}
//Method Where I save self.thumb in app documents
-(void) saveImage:(UIImage*)image withName:(NSString*)fileName
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//Save Image
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",fileName]];
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil];
}
上記は私のコードです。 2つの録音で遅延がない場合、self.thumbは正しく保存されません。
コードを掲載してください。 –
コードで質問を更新しました。 – Yogi
私は、ゼロの時間がサムネイルを作成するのに時間がかかることを発見しました。クリップが短い場合を除き、 'CMTimeMakeWithSeconds(1,1)'の時間を使ってみてください。 – jessecurry