我正在尝试将视频的第一帧捕获为UIImageView,以便在整个应用中使用。什么是完成这个的赌注?
答案 0 :(得分: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
我希望它会有所帮助。
答案 1 :(得分: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;
}
答案 2 :(得分:0)
以下是代码,您可以通过视频网址获取录制视频的缩略图。
MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL:videoURL]autorelease];
UIImage *thumbnail = [player thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame];