简体   繁体   English

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

[英]Is there any way other than thumbnail method to take a screenshot of an video in Iphone?

Is there any way other than thumbnail method to take a screenshot of an video? 除了缩略图方法之外还有其他方法可以截取视频吗? If yes then please tell me if not then please tell me how to resize an thumbnail image with a same resolution? 如果是,那么请告诉我,如果没有,那么请告诉我如何调整具有相同分辨率的缩略图图像? i have getting an issue while taking screenshot of video.i have used this:- 我在拍摄视频截图时遇到了问题。我使用过:

How to take a screenshot from an video playing through MPMediaPlayerController in iPhone? 如何通过iPhone中的MPMediaPlayerController播放视频截图?

After this i ve used merging of an image by which i'm getting this 在此之后,我使用合并的图像,我得到了这个 解决问题

here image quality is my big issue. 这里的图像质量是我的大问题。

I want this 我要这个

要求的输出

I want only video and drawing shown in above screenshot with same resultion. 我只想要在上面的屏幕截图中显示的视频和绘图具有相同的结果。 Please help Thanks :) 请帮忙谢谢:)

There is a way other than thumbnail method by which i can get screenshot of a video.!!! 除了缩略图方法之外,还有一种方法可以获取视频的屏幕截图。!!!

The way is this :- 方式是这样的: -

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

But still my problem is same im drawing on video i cant get video's screenshot with drawing overlay,so for that i ve to use merging of images. 但仍然我的问题是相同的我在绘制视频我不能得到视频的截图与绘图叠加,所以为此,我使用合并的图像。

Thanks :) 谢谢 :)

Try the following code. 请尝试以下代码。

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

This will give you the screen shot of your video player at point of time you want. 这将为您提供所需时间的视频播放器屏幕截图。 And it's a standard method the to get the thumbnail of player with the time option. 并且它是一种标准方法,可以通过时间选项获取播放器的缩略图。

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)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM