iphone - 在 iPhone 上获取流媒体视频的屏幕截图

标签 iphone objective-c ipad

如何在 iphone 上获取流媒体视频的屏幕截图。我尝试了几种方法。

  1. UIGetScreenImage() -> 这是私有(private)的。如果我使用该应用程序,它将被拒绝。

  2. UIGraphicsBeginImageContext(CGSizeMake(1024, 768)); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();

    The code above cannot take the screenshot of video layer.
    
  3. 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/

相关文章:

iphone - 防止 UITabBar 将渐变应用于其图标图像

iphone - 为每个 Spotify 用户加载仅由一个用户创建的播放列表

ios - 在Xcode 7中添加opencv框架,出现问题框架未找到opencv2

ipad - UITableView背景颜色

iphone - 企业分发提示消息说(null)想安装{app name}

iphone - 如何使用 Objective C 为 iOS 设备编写我自己的下载管理器

iphone - iOS中将键值对添加到plist文件时出现问题

iphone - UIScrollViewDelegate 未触发

ios - 滑动删除按钮位于自定义 UITableViewCell 文本下方

iphone - 检查文件是否更新