【问题标题】:Is there any way other than thumbnail method to take a screenshot of an video in Iphone?除了缩略图方法之外,还有其他方法可以在 Iphone 中截取视频吗?
【发布时间】:2012-05-23 16:00:41
【问题描述】:
【问题讨论】:
标签:
iphone
objective-c
image-capture
【解决方案1】:
除了缩略图之外,还有其他方法可以截取视频。!!!
方法是这样的:-
- (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;
}
但我的问题仍然是相同的,我在视频上绘图我无法通过绘图叠加获得视频的屏幕截图,因此我必须使用图像合并。
谢谢:)
【解决方案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];
【解决方案3】:
这将在您想要的时间点为您提供视频播放器的屏幕截图。
这是一个标准的方法,通过时间选项来获取玩家的缩略图。
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)];