[英]Get the screenshot of a streaming video on iphone
如何在iphone上獲取流媒體視頻的屏幕截圖。 我嘗試了幾種方法。
UIGetScreenImage() - >這是私有的。 如果我使用該應用程序將被拒絕。
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];
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];
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.