在iphone上获取流媒体视频的屏幕截图 [英] Get the screenshot of a streaming video on iphone

查看:581
本文介绍了在iphone上获取流媒体视频的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can i get the screenshot of a streaming video on iphone. I tried several methods.


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

  1. UIGetScreenImage() -> This is private. The app will be rejected if I use it.

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

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];

  • 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,我还能尝试什么?谢谢。

    What else can I try besides AVFoundation. Thank you.

    推荐答案

    不确定它是否可行,但您尝试过使用AVPlayer吗?它应该允许您访问AVURLAsset,您可以将其传递给AVAssetImageGenerator。

    Not sure if it will work, but have you tried using AVPlayer? It should give you access to AVURLAsset which you could pass to 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上获取流媒体视频的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆