gpt4 book ai didi

swift - "CIImage initWithCVPixelBuffer:options:"失败,因为 iOS 10 不支持其像素格式 p422

转载 作者:搜寻专家 更新时间:2023-10-31 22:30:20 25 4
gpt4 key购买 nike

在ios10中,我想获取视频采集,但是得到一个错误“[CIImage initWithCVPixelBuffer:options:] failed because its pixel format p422 is not supported.”

我的代码是这样的:

func previewImage(handle: (image: UIImage?) -> Void) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
guard let time = self.player?.currentTime() else {
return
}
guard let pixelBuffer = self.output?.copyPixelBufferForItemTime(time,
itemTimeForDisplay: nil) else {
return
}
let ciImage = CIImage(CVPixelBuffer: pixelBuffer)
let temporaryContext = CIContext(options: nil)
let rect = CGRectMake(
0,
0,
CGFloat(CVPixelBufferGetWidth(pixelBuffer)),
CGFloat(CVPixelBufferGetHeight(pixelBuffer))
)

let image: UIImage?
if let videoImage = temporaryContext.createCGImage(ciImage, fromRect: rect) {
image = UIImage(CGImage: videoImage)
}
else {
image = nil
}
handle(image: image)
})
})

}

得到这样的错误:

enter image description here

我该怎么办😲😲😲😲😲😲😲?

最佳答案

你能展示一下你是如何设置你的 AVPlayerItemVideoOutput 的吗?

看起来您正在使用某种(我不知道,p422?)类型的 4:2:2 格式,而不是更兼容的格式,例如 kCVPixelFormatType_420YpCbCr8BiPlanarFullRangekCVPixelFormatType_32BGRA.

关于swift - "CIImage initWithCVPixelBuffer:options:"失败,因为 iOS 10 不支持其像素格式 p422,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39610767/

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