Getting Thumbnails for iPhone

How to get a thumbnail of a video imported from a camera roll or the camera itself?

This was asked earlier and was answered. However, the answers kind of suck me.

This stream iphone sdk> 3.0. Video thumbnail? has several options, which boil down to:

  • Bypass some JPG file system directories with the last change date, which should match the video you just selected. This is very messy and involves rooting in directories that Apple probably won't want me to do.
  • Use ffmpeg. But this is so general that I cannot understand what steps will be required to import ffmpeg into my project and actually call it to extract the images.

Is there no other way? This seems to be HUGE supervision in the SDK for me. I mean, there are thumbnails in the video picker, so Apple has to do something to generate them, but doesn't let us?

+3
source share
3 answers

The best method I found ... MPMoviePlayerController thumbnailImageAtTime: timeOption

Don't worry about it ... see the first comment below. This is the answer.

+3
source
     -(void)testGenerateThumbNailDataWithVideo {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"IMG_0106" ofType:@"MOV"];
 NSURL *url = [NSURL fileURLWithPath:path];
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
    AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    NSError *err = NULL;
    CMTime time = CMTimeMake(1, 60);
    CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
    [generate release];
    NSLog(@"err==%@, imageRef==%@", err, imgRef);
    UIImage *currentImg = [[UIImage alloc] initWithCGImage:imgRef];
    static BOOL flag = YES;
    if (flag) { 
        NSData *tmpData =   UIImageJPEGRepresentation(currentImg, 0.8);
        NSString *path = [NSString stringWithFormat:@"%@thumbNail.png", NSTemporaryDirectory()];
        BOOL ret = [tmpData writeToFile:path atomically:YES]; 
        NSLog(@"write to path=%@, flag=%d", path, ret);
        flag = NO;
    }
    [currentImg release]; 
}
+12
source

ffmpeg, , , .

, ffmpeg . , , - . http://sol3.typepad.com/tagalong_developer_journa/

This tutorial here has helped us and perhaps most of the developers using ffmpeg to get started. dranger.com/ffmpeg/ "

Finally,

Apple probably won't have a problem using a thumbnail created using a camcorder, but I don't think that only the camera creates it in the private folder, not the video selected from the image picker.

+1
source

All Articles