[英]Get the screenshot of a streaming video on iphone
如何在iphone上获取流媒体视频的屏幕截图。 我尝试了几种方法。
UIGetScreenImage() - >这是私有的。 如果我使用该应用程序将被拒绝。
UIGraphicsBeginImageContext(CGSizeMake(1024,768)); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
The code above cannot take the screenshot of video layer.
MPMoviePlayerController * movie = [[MPMoviePlayerController alloc] initWithContentURL [NSURL URLWithString:@“myMovie.mp4”]]; UIImage * singleFrameImage = [movie thumbnailImageAtTime:10 timeOption:MPMovieTimeOptionExact];
The code above does not work on a streaming video.
除了AVFoundation,我还能尝试什么? 谢谢。
不确定它是否可行,但你尝试过使用AVPlayer吗? 它应该允许您访问AVURLAsset,您可以将其传递给AVAssetImageGenerator。
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:yourURL];
AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];
//observe 'status'
[playerItem addObserver:self forKeyPath:@"status" options:0 context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"status"]) {
AVPlayerItem *item = (AVPlayerItem *)object;
if (item.status == AVPlayerItemStatusReadyToPlay) {
AVURLAsset *asset = (AVURLAsset *)item.asset;
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
CGImageRef thumb = [imageGenerator copyCGImageAtTime:CMTimeMakeWithSeconds(10.0, 1.0)
actualTime:NULL
error:NULL];
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.