如何在 iphone 上获取流媒体视频的屏幕截图。我尝试了几种方法。
UIGetScreenImage() -> 这是私有(private)的。如果我使用该应用程序,它将被拒绝。
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 分配] initWithContentURL [NSURL URLWithString:@"myMovie.mp4"]]; UIImage *singleFrameImage = [movie thumbnailImageAtTime:10 时间选项: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];
}
}
}
关于iphone - 在 iPhone 上获取流媒体视频的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5388226/