【问题标题】:Get the screenshot of a streaming video on iphone在 iphone 上获取流媒体视频的屏幕截图
【发布时间】:2011-07-20 06:46:00
【问题描述】:

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

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

  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 alloc] initWithContentURL [NSURL URLWithString:@"myMovie.mp4"]]; UIImage *singleFrameImage = [电影缩略图ImageAtTime:10 timeOption:MPMovieTimeOptionExact];

    The code above does not work on a streaming video.
    

除了 AVFoundation,我还能尝试什么。谢谢。

【问题讨论】:

  • 我自己没有尝试过,但也许可以查看 CALayer 并将其保存为图像或读取它的每个像素并将其保存到图像中?

标签: iphone objective-c ipad


【解决方案1】:

不确定它是否会起作用,但您是否尝试过使用 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];
        }
    }   
}

【讨论】:

  • 您也可以尝试在 AVPlayerLayer 上使用 renderInContext:。
  • 另外添加一行:imageGenerator.appliesPreferredTrackTransform = YES;如果播放的视频有不同的旋转。
  • 确保 CGImageRelease(thumb); (也在 ARC 中)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-11
  • 1970-01-01
相关资源
最近更新 更多