 }
 
 public func SaveAsMPEG4(images: [CGImage], to dir: String, with name: String,
-    and fps: Int) {
-        images.saveAsMPEG4(to: dir, with: name, and: fps)
+    fps: Int, _ pixelFormat: Int = kCVPixelFormatType_32BGRA) {
+        images.saveAsMPEG4(to: dir, with: name, fps, pixelFormat)
 }
 
 public func SaveAsPNG(images: [CGImage], to dir: String, with name: String) {

            }

            for t in self {
                let buffer = (t as! CGImage).toCVPixelBuffer()
                let time = getTime()
                ExponentialBackoff(isReady, 0.1, 2.0) {
                    adaptor.appendPixelBuffer(buffer, withPresentationTime: time)
                }
                count++
            }

            input.markAsFinished()
            video.endSessionAtSourceTime(getTime())
            video.finishWritingWithCompletionHandler(nil)
    }

}


    // ADD: async execution, completed callback
    func saveAsMPEG4<T: CGImage>(to dir: String, with name: String,
        _ fps: Int, _ pixelFormat: Int = kCVPixelFormatType_32BGRA) {

            if self.count == 0 {
                return
            }

            let url = NSURL(fileURLWithPath: "\(dir)\(name).mp4")
            let video = AVAssetWriter(URL: url, fileType: AVFileTypeMPEG4,
                error: nil)

            let first = self.first! as! CGImage
            let width = CGImageGetWidth(first)
            let height = CGImageGetHeight(first)
            let osPixelFormat = OSType(pixelFormat)

            let settings = [
                AVVideoCodecKey: AVVideoCodecH264,
