2012-05-16 20 views
12

除縮略圖方法以外,還有其他方法可以拍攝視頻的截圖嗎?如果是,那麼請告訴我,如果沒有,那麼請告訴我如何調整具有相同分辨率的縮略圖圖像?我也得到一個問題,同時考慮video.i的截圖已經使用這樣的: -除了縮略圖方法,還有其他方法可以在iPhone中拍攝視頻的截圖嗎?

How to take a screenshot from an video playing through MPMediaPlayerController in iPhone?

在此之後我已經圖像的使用合併由我得到這個Resolution problem

這裏的圖像質量是我的大問題。

我想這

Required Output

我想唯一的視頻,並與同resultion上面的截圖所示圖紙。 請幫助謝謝:)

回答

6

除縮略圖方法外,還有一種方法可以獲取視頻的截圖。

的方式是這樣的: -

- (UIImage *)imageFromVideoURL 
{ 
// result 
UIImage *image = nil; 

// AVAssetImageGenerator 
AVAsset *asset = [[AVURLAsset alloc] initWithURL:appDelegate.videoURL options:nil];; 
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; 
imageGenerator.appliesPreferredTrackTransform = YES; 

// calc midpoint time of video 
Float64 durationSeconds = CMTimeGetSeconds([asset duration]); 
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600); 

// get the image from 
NSError *error = nil; 
CMTime actualTime; 
CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error]; 

if (halfWayImage != NULL) 
{ 
    // cgimage to uiimage 
    image = [[UIImage alloc] initWithCGImage:halfWayImage]; 
    [dic setValue:image forKey:kImage]; 
    NSLog(@"Values of dictonary==>%@", dic); 
    NSLog(@"Videos Are:%@",appDelegate.videoURLArray); 
    CGImageRelease(halfWayImage); 
} 
return image; 
} 

但是還是我的問題是相同的I M上的視頻我不能讓視頻的截圖與繪製覆蓋繪製,所以,我已經使用圖像的合併。

謝謝:)

2

請嘗試下面的代碼。

moviePlayer = [[MPMoviePlayerController alloc] init]; 
    containerView =[[UIView alloc]initWithFrame:CGRectMake(40,130, 240,219)]; 
    [moviePlayer setContentURL:[NSURL fileURLWithPath:moviePath]]; 
    [[moviePlayer view] setFrame:CGRectMake(0, 0, containerView.frame.size.width, containerView.frame.size.height)]; // frame must match parent view 
    [self.view addSubview:containerView]; 
    [containerView addSubview: [moviePlayer view]]; 
    [moviePlayer setFullscreen:YES animated:YES]; 
2

這會給您的視頻播放器的屏幕快照在你想要的時間點。 這是一個用時間選項獲得玩家縮略圖的標準方法。

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


UIImageView *imagV=[[UIImageView alloc]initWithImage:thumbnail]; 
[imagV setFrame:CGRectMake(self.view.center.x, self.view.center.y, 200.0, 200.0)]; 
相關問題