Posts

Post not yet marked as solved
6 Replies
0 Views
Thanks! I'll see what i can do. I appreciate your taking the tme.
Post not yet marked as solved
6 Replies
0 Views
Thanks for the further reply, Quincey. I found the reference identifying kCVPixelFormatType_422YpCbCr8_yuvs as YUY2 at a random link, it may be incorrect. Not sure how to determine the correct one though.Could you perhaps demonstrate the code? I'm relatively junior, and I'm having trouble picturing exactly what you are recommending, though I am extremely eager to learn. The methods for creating a CVPixelBuffer all require the PixelFormatType like kCVPixelFormatType_422YpCbCr8_yuvs, and I can't see how to copy bytes into a CVPixelBuffer other than at creation. Or do i lock the base address and use memcpy?
Post not yet marked as solved
6 Replies
0 Views
Thanks! So I am trying the following in a test app, in the ViewController, but it's not working. Any ideas? var url: URL! var buffer: Data! override func viewDidLoad() { super.viewDidLoad() let path = Bundle.main.path(forResource: "gst-video", ofType: "yuy2")! self.url = URL(fileURLWithPath: path) // According to a hex editor, each frame is 614400 long let data = try! Data(contentsOf: self.url) let sub = data.subdata(in: 0..<614400) self.buffer = sub } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) var pixelBufferOut: CVPixelBuffer? let attributes : [NSObject:AnyObject] = [ kCVPixelBufferCGImageCompatibilityKey : true as AnyObject, kCVPixelBufferCGBitmapContextCompatibilityKey : true as AnyObject ] CVPixelBufferCreateWithBytes(kCFAllocatorDefault, 640, 480, kCVPixelFormatType_422YpCbCr8_yuvs, UnsafeMutablePointer(&buffer), 8, nil, nil, attributes as CFDictionary, &pixelBufferOut) guard let pixelBuffer = pixelBufferOut else { return } let ciImage = CIImage(cvPixelBuffer: pixelBuffer) let ciContext = CIContext(options: nil) let frameImage = ciContext.createCGImage(ciImage, from: ciImage.extent) let frame = UIImage(cgImage: frameImage!)The frame is not a valid video frame, it's a bunch of color bands.