每次我尝试从我的视频资产生成静止帧时,它都会在 0.000.. 秒的时间生成。我可以从我的日志消息中看到这一点。好消息是我可以在时间 0.000.. 获取图像以显示在名为“myImageView”的 UIImageView 中。我认为问题是 AVURLAssetPreferPreciseDurationAndTimingKey 没有设置,但即使我想出了如何做到这一点,它仍然不起作用..
这是我所拥有的..
time、actualTime 和 generate 在 Header 中声明
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
…………………………………………………………………………………………
非常感谢你们提前.. :)