2012-05-16 12 views
12

サムネイル以外の方法で動画のスクリーンショットを撮る方法はありますか?はいの場合は、同じ解像度でサムネイル画像のサイズを変更する方法を教えてください。私はvideo.iのスクリーンショットをしながら問題を取得して、この使用していています - 私はこのResolution problemiphoneでビデオのスクリーンショットを撮るサムネイル以外の方法はありますか?

ここで画質を取得していたことで、画像の使用マージVEのこの後

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

を私の大きな問題です。

私は同じresultionと上記のスクリーンショットに示す唯一のビデオや描画をしたい、この

Required Output

をしたいです。 助けてくださいありがとう:)

答えて

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; 
} 

しかし、それでもまだ、私の問題は私が画像のマージを使用しましそのため私は、オーバーレイを描画して、ビデオのスクリーンショットを取得カントビデオに描く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)]; 
関連する問題