AFathi / ARVideoKit

Capture & record ARKit videos 📹, photos 🌄, Live Photos 🎇, and GIFs 🎆.
Apache License 2.0
1.62k stars 226 forks source link

Resolve errors #93

Closed digitallysavvy closed 4 years ago

digitallysavvy commented 4 years ago

Appending directly to AVAssetWriterInputPixelBufferAdaptor using:

func append(pixel buffer:CVPixelBuffer, with time: CMTime) {
        pixelBufferInput.append(buffer, withPresentationTime: time)
}

was causing the writer to fail unexpectedly after writing the first frame. By using a PixelBufferPool the writer runs without issue.

func append(pixel buffer:CVPixelBuffer, with time: CMTime) {
        var appendSucceeded = false
        autoreleasepool {
            if let _ = pixelBufferInput.pixelBufferPool {
                appendSucceeded = pixelBufferInput.append(
                    buffer,
                    withPresentationTime: time
                )
            }
        }
        logAR.message("append to pixel buffer: \(appendSucceeded)")
    }

after resolving buffer pool, pixel format started causing writer to fail, so updated sourcePixelBufferAttributes to:

let attributes : [String:Any] = [
        kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32ARGB),
        kCVPixelBufferCGImageCompatibilityKey as String : true,
        kCVPixelBufferCGBitmapContextCompatibilityKey as String : true
]

Other: Latest version of Xcode was throwing errors and warning for renamed enums, types, etc. Resolved all errors and warnings. Builds for iOS 12 (hopefully this resolves #92)