I'm stuck for weeks!
I tried all of the solutions out there on stackoverflow which they work fine for around ~ 0 to 500 images or 50 seconds on 12 fps, but for longer videos there's black flickering after ~50 seconds depending on what iphone, with iphone 6 happens after 50 sec on iphone 8 it happens after 1:30
I tried the accepted answer from this link writeImagesAsMovie()
function
sometimes I get memory allocation problem, sometimes I don't, But the black flickering persists.
// MARK: - Fill Pixel Buffer -
private func fillPixelBufferFromImage(image: UIImage, pixelBuffer: CVPixelBuffer) {
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer)
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
// Create CGBitmapContext
let context = CGContext(
data: pixelData,
width: Int(720),
height: Int(720),
bitsPerComponent: 8,
bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer),
space: rgbColorSpace,
bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue
)
// Draw image into context"
context?.draw(image.cgImage!, in: CGRect(x: 0, y: 0, width: 720, height: 720))
CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
//UIGraphicsEndImageContext()
}