gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:38:03 28 4
gpt4 key购买 nike

如何在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com