除了缩略图方法之外还有其他方法可以在Iphone中截取视频吗?

时间:2012-05-16 05:38:38

标签: iphone objective-c image-capture

除缩略图方法之外还有其他方法可以截取视频吗?如果是,那么请告诉我,如果没有,那么请告诉我如何调整具有相同分辨率的缩略图图像?我在拍摄视频截图时遇到了问题。我使用了这个: -

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

在此之后,我使用了合并我得到此Resolution problem

的图像

这里的图像质量是我的大问题。

我想要这个

Required Output

我只希望上面屏幕截图中显示的视频和绘图具有相同的结果。 请帮忙谢谢:)

3 个答案:

答案 0 :(得分: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;
}

但我的问题仍然是我在绘制视频时我无法获得带有绘图叠加的视频截图,所以我必须使用合并图像。

谢谢:)

答案 1 :(得分: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 :(得分: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)];
相关问题