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