Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iphone上获取流媒体视频的屏幕截图_Iphone_Objective C_Ipad - Fatal编程技术网

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

在iphone上获取流媒体视频的屏幕截图,iphone,objective-c,ipad,Iphone,Objective C,Ipad,如何在iphone上获取流媒体视频的屏幕截图。我尝试了几种方法 UIGetScreenImage()->这是私有的。如果我使用该应用程序,它将被拒绝 UIGraphicsBeginImageContext(CGSizeMake(1024768)); [self.view.layer renderContext:UIGraphicsGetCurrentContext()]; UIImage*viewImage=UIGraphicsGetImageFromCurrentImageContext();

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

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

  • UIGraphicsBeginImageContext(CGSizeMake(1024768)); [self.view.layer renderContext:UIGraphicsGetCurrentContext()]; UIImage*viewImage=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsSendImageContext()

  • MPMoviePlayerController*电影=[[MPMoviePlayerController alloc] initWithContentURL[nsurlUrlWithString:@“myMovie.mp4”]; UIImage*singleFrameImage=[movie ThumbnailImageTime: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];
            }
        }   
    }
    

    我自己还没有尝试过,但也许可以查看CALayer并将其保存为图像,或者读取其中的每个像素并将其保存为图像?也可以尝试在AVPlayerLayer上使用RenderContext:。还可以添加行:imageGenerator.appliesPreferredTrackTransform=YES;如果播放的视频具有不同的旋转。请确保CGImageRelease(拇指);(也在ARC中)
    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];
            }
        }   
    }