English 中文(简体)
Can t有AVAssetImageGenerator给我一个电影的所有框架。
原标题:Can t have AVAssetImageGenerator give me all the frames of a movie

页: 1 给我所有的电影。

使用该守则:

NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mov"];
NSURL *url=[NSURL fileURLWithPath:path];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
self.asset=[[AVURLAsset alloc] initWithURL:url options:options];

NSMutableArray *thumbTimes=[NSMutableArray arrayWithCapacity:asset.duration.value];
for(int t=0;t < asset.duration.value;t++) {
    CMTime thumbTime = CMTimeMake(t,asset.duration.timescale);
    NSValue *v=[NSValue valueWithCMTime:thumbTime];
    [thumbTimes addObject:v];
}
self.generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
self.generator.appliesPreferredTrackTransform=TRUE;
self.generator.requestedTimeToleranceAfter=kCMTimeZero;
self.generator.requestedTimeToleranceBefore=kCMTimeZero;


AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
    if (result != AVAssetImageGeneratorSucceeded) {
        NSLog(@"couldn t generate thumbnail, error:%@", error);
    }
    NSLog(@"actual time: %lld/%d (requested: %lld/%d)",actualTime.value,actualTime.timescale,requestedTime.value,requestedTime.timescale);
};
CGSize maxSize = CGSizeMake(320, 180);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:thumbTimes completionHandler:handler];

我收到了:

2012-04-19 18:55:06.801 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 0/600)
2012-04-19 18:55:07.836 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 1/600)
2012-04-19 18:55:08.314 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 2/600)
2012-04-19 18:55:09.350 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 3/600)
2012-04-19 18:55:10.186 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 4/600)
2012-04-19 18:55:11.257 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 5/600)
2012-04-19 18:55:11.697 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 6/600)
2012-04-19 18:55:12.246 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 7/600)
2012-04-19 18:55:13.255 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 8/600)
2012-04-19 18:55:14.513 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 9/600)
2012-04-19 18:55:15.944 OpenCVClient[77273:13b07] actual time: -9/600 (requested: 10/600)
2012-04-19 18:55:17.230 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 11/600)
2012-04-19 18:55:17.995 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 12/600)
2012-04-19 18:55:18.716 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 13/600)
2012-04-19 18:55:19.399 OpenCVClient[77273:13b07] actual time: 11/600 (requested: 14/600)

如您在守则一中看到的那样,VURLAssetPrefer PreciseDurationAndTimingKey,requestedtime ToleranceBefore and requestedtime ToleranceAfter, no effect.

任何想法?

最佳回答

有了你的密码,你就获得了所有电影。 所要求的时间和实际时间之间的差别是由电影制成的。 看来,你的电影有大约25-29秒钟。 例如,在1/600s和8/600s之间,存在一定差异。

问题回答
    //loading image
    NSString *initialURL = [NSString stringWithFormat:@"%@",[arrayURL objectAtIndex:indexPath.row]];
    NSURL *url=[NSURL fileURLWithPath:initialURL];
    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
    self.asset=[[AVURLAsset alloc] initWithURL:url options:options];

    NSMutableArray *thumbTimes=[NSMutableArray arrayWithCapacity:asset.duration.value];
    CMTime thumbTime = CMTimeMake(1,1);
    NSValue *v=[NSValue valueWithCMTime:thumbTime];
    [thumbTimes addObject:v];

    self.imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    self.imageGenerator.appliesPreferredTrackTransform=TRUE;
    self.imageGenerator.requestedTimeToleranceAfter=kCMTimeZero;
    self.imageGenerator.requestedTimeToleranceBefore=kCMTimeZero;


    AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
        if (result != AVAssetImageGeneratorSucceeded) {
            NSLog(@"couldn t generate thumbnail, error:%@", error);
        }
        NSLog(@"actual time: %lld/%d (requested: %lld/%d)",actualTime.value,actualTime.timescale,requestedTime.value,requestedTime.timescale);

        //your image view
        imageView.image = [UIImage imageWithCGImage:im];
    };
    CGSize maxSize = CGSizeMake(320, 180);
    imageGenerator.maximumSize = maxSize;
    [imageGenerator generateCGImagesAsynchronouslyForTimes:thumbTimes completionHandler:handler];
    //loaging complete




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签