gpt4 book ai didi

ios - AVPlayer 播放 m3u8 流时如何捕获图像?

转载 作者:可可西里 更新时间:2023-11-01 05:40:44 25 4
gpt4 key购买 nike

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

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);
}

但它不起作用。错误是:

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}

我该如何解决?
非常感谢。

最佳答案

AVAssetImageGenerator 可能需要本地资源。将 AVPlayerItemVideoOutput 添加到您的 AVPlayer,寻找所需位置并在 videoOutput 上调用 copyPixelBufferForItemTime:itemTimeForDisplay: 可能会更幸运。

关于ios - AVPlayer 播放 m3u8 流时如何捕获图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29404060/

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