问题
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?
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 :)
回答1:
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 i m drawing on video i cant get video's screenshot with drawing overlay,so for that i ve to use merging of images.
Thanks :)
回答2:
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];
回答3:
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)];
来源:https://stackoverflow.com/questions/10612634/is-there-any-way-other-than-thumbnail-method-to-take-a-screenshot-of-an-video-in