Reputation: 111
In ios10 , I want to get video capture, but get an error "[CIImage initWithCVPixelBuffer:options:] failed because its pixel format p422 is not supported."
My code is this:
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)
})
})
}
get an error like this :
what should I do 😲😲😲😲😲😲😲?
Upvotes: 4
Views: 2334
Reputation: 36074
Can you show how you're setting up your AVPlayerItemVideoOutput
?
It looks like you're using some (unknown to me, p422?) kind of 4:2:2 format instead of a more compatible one like kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
or kCVPixelFormatType_32BGRA
.
Upvotes: 3