当AVPlayer播放m3u8流时如何捕获图像? [英] How can I capture an image when AVPlayer playing m3u8 stream?

查看:799
本文介绍了当AVPlayer播放m3u8流时如何捕获图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AVPlayer 来播放 m3u8 文件,我想在这些代码中捕获图像:

I use AVPlayer to play a m3u8 file, and I want to capture an image in these code:

AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:self.player.currentItem.asset];
gen.appliesPreferredTrackTransform = YES;
NSError *error = nil;
CMTime actualTime;
CMTime now = self.player.currentTime;
[gen setRequestedTimeToleranceAfter:kCMTimeZero];
[gen setRequestedTimeToleranceBefore:kCMTimeZero];
CGImageRef image = [gen copyCGImageAtTime:now actualTime:&actualTime error:&error];
UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
NSLog(@"%f , %f",CMTimeGetSeconds(now),CMTimeGetSeconds(actualTime));

NSLog(@"%@",error);
if (image) {
    CFRelease(image);
}

但它不起作用。错误是:

but it does not work. And the error is:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x7fadf25f59f0 {NSUnderlyingError=0x7fadf25f1670 "The operation couldn’t be completed. (OSStatus error -12782.)", NSLocalizedFailureReason=An unknown error occurred (-12782), NSLocalizedDescription=The operation could not be completed}

我该如何解决?

非常感谢。

How can I solve it?
Thanks a lot.

推荐答案

AVAssetImageGenerator 可能需要本地资产。也许你有更多的运气将 AVPlayerItemVideoOutput 添加到你的 AVPlayer ,寻找所需的地点并致电<$ c视频输出上的$ c> copyPixelBufferForItemTime:itemTimeForDisplay:。

AVAssetImageGenerator may require local assets. Maybe you'd have more luck adding an AVPlayerItemVideoOutput to your AVPlayer, seeking to the desired spot and calling copyPixelBufferForItemTime:itemTimeForDisplay: on the videoOutput.

这篇关于当AVPlayer播放m3u8流时如何捕获图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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