ビデオ アセットから静止フレームを生成しようとするたびに、0.000.. 秒の時点で生成されます。これは、ログ メッセージから確認できます。良いことは、時間 0.000 の画像を取得して、"myImageView" という UIImageView に表示できることです。問題は AVURLAssetPreferPreciseDurationAndTimingKey が設定されていないことだと思いましたが、その方法を理解した後でもまだ機能しません..
これが私が持っているものです..
time、actualTime、および generate はヘッダーで宣言されています
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/videoTest4.m4v"]];
//UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
NSURL *url = [NSURL fileURLWithPath:path];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:options];
Float64 durationSeconds = CMTimeGetSeconds([asset duration]);
generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *err = nil;
time = CMTimeMake(600,600.0);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:&actualTime error:&err];
UIImage *currentImg = [[UIImage alloc] initWithCGImage:imgRef];
myImageView.image = currentImg;
NSLog(@"The total Video Duration is %f",durationSeconds);
NSLog(@"The time I want my image is %f",CMTimeGetSeconds(time));
NSLog(@"The actual time my image was take was %f",CMTimeGetSeconds(actualTime));
そして私のコンソールは..
2011-04-28 18:49:59.062 videoTest[26553:207] 合計ビデオ期間は 1.880000 です
2011-04-28 18:49:59.064 videoTest[26553:207] 画像が必要な時間は 1.000000 です
2011-04-28 18:49:59.064 videoTest[26553:207] 私の画像が撮影された実際の時間は 0.000000 でした
...................................
どうもありがとうございました.. :)