2013-10-02 119 views
-2

我想捕獲視頻的第一幀作爲UIImageView在整個應用程序中使用。下注的方式是什麼?爲視頻創建縮略圖

+0

我認爲[這] [1]仍然是相關 [1]:http://stackoverflow.com/questions/7501413/create-thumbnail-from-a-video-url-in- iphone-sdk –

回答

0

傳遞視頻網址,該網址反過來返回視頻的縮略圖。

-(UIImage *)getThumbNail:(NSString)stringPath 
{ 
    NSURL *videoURL = [NSURL fileURLWithPath:stringPath]; 

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 

    UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 

    //Player autoplays audio on init 
    [player stop]; 
    [player release]; 
    return thumbnail; 
} 
0

這裏是代碼如何獲得您只需傳遞視頻網址的錄製視頻的縮略圖。

MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL]autorelease]; 
UIImage *thumbnail = [player thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 
1

在我的應用程序使用此代碼:

#import <AssetsLibrary/AssetsLibrary.h> 
#import <AVFoundation/AVFoundation.h> 
#import <AudioToolbox/AudioToolbox.h> 
#import <CoreMedia/CoreMedia.h> 
#import <MediaPlayer/MediaPlayer.h> 

//create thumbnail from video 


AVAsset *asset = [AVAsset assetWithURL:url];// url= give your url video here 
    AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset]; 
    CMTime time = CMTimeMake(1, 5);//it will create the thumbnail after the 5 sec of video 
    CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL]; 
    UIImage *thumbnail = [UIImage imageWithCGImage:imageRef]; 
    cell.backGround.image=thumbnail;// whichever imageview you want give this image 

我希望這將有所幫助。

+0

需要添加什麼框架才能工作,每行都有錯誤@Dev Patel –

+0

檢查我編輯的答案:可能會添加#import ,#import 。 –

+0

隨着那些導入,我仍然在CMTime –