从电影中获取缩略图

时间:2013-06-27 10:28:54

标签: ios video

我有一个应用程序,我可以拍摄视频,然后将其存储在核心数据中以及其他一些数据。它存储为Transformable和" Store in External Record File"。我把视频剪辑放到像这样的电影对象中;

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
     movie = [info objectForKey:UIImagePickerControllerEditedImage];

我遇到的问题是从电影中获取缩略图。使用MPMoviePlayerController我必须有一个URL,但电影还没有存储在任何地方。另外,从核心数据中查找URL也是一个谜。

我在这里找到的最近的帮助是Getting a thumbnail from a video url or data in iPhone SDK。但我对URL问题感到困惑。

我将它保存到这样的核心数据中;

     NSManagedObjectContext *context = [self managedObjectContext];
     NSManagedObject *newMedia = [NSEntityDescriptioninsertNewObjectForEntityForName:@"Media" inManagedObjectContext:context];
     [newMedia setValue:@"Video Clip " forKey:@"title"];
     [newMedia setValue:now forKey:@"date_time"];
     [newMedia setValue:movie forKey:@"movie"];
     [newMedia setValue:[self generateImage] forKey:@"frame"];

如果有人可以给我一个指针,我将不胜感激。

3 个答案:

答案 0 :(得分:2)

我在我的应用中使用了这样的

- (UIImage *)imageFromMovie:(NSURL *)movieURL atTime:(NSTimeInterval)time {
    // set up the movie player
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] 
                                   initWithContentURL:movieURL];
    mp.shouldAutoplay = NO;
    mp.initialPlaybackTime = time;
    mp.currentPlaybackTime = time;
    // get the thumbnail
    UIImage *thumbnail = [mp thumbnailImageAtTime:time 
                                       timeOption:MPMovieTimeOptionNearestKeyFrame];
    // clean up the movie player
    [mp stop];
    [mp release];
    return(thumbnail);
}

一样使用
imageView.image = [self imageFromMovie:fileURL atTime:10.0];

答案 1 :(得分:1)

您可以像这样获取电影网址,然后使用此网址通过MPMoviePlayerController获取缩略图。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ;
     . .. .
     .. .. 
 }

答案 2 :(得分:1)

从电影中获取缩略图......

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if ([[info objectForKey:@"UIImagePickerControllerMediaType"] rangeOfString:@"movie"].location!=NSNotFound)
 {
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];
    theMovie.view.frame = self.view.bounds;
    theMovie.controlStyle = MPMovieControlStyleNone;
    theMovie.shouldAutoplay=NO;
    UIImage *imgTemp = [theMovie thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionExact];
 }
}