         }
     }
 
-    private func makePixelBufferAdaptor(assetWriterInput input: AVAssetWriterInput,videoTrackSettings settings: [String: AnyObject]) -> AVAssetWriterInputPixelBufferAdaptor {
-
-        let videoWidth = max(settings[AVVideoWidthKey] as! Int, settings[AVVideoHeightKey] as! Int)
-        let videoHeight = min(settings[AVVideoWidthKey] as! Int, settings[AVVideoHeightKey] as! Int)
+    private func makePixelBufferAdaptor(assetWriterInput input: AVAssetWriterInput, videoDimensions: CMVideoDimensions) -> AVAssetWriterInputPixelBufferAdaptor {
+
+        let pixelBufferWidth = max(videoDimensions.height, videoDimensions.width)
+        let pixelBufferHeight = min(videoDimensions.height, videoDimensions.width)
 
         // Use BGRA for the video in order to get realtime encoding.
-
-        let sourcePixelBufferAttributes = [
+        let sourcePixelBufferAttributes: [String: AnyObject] = [
             String(kCVPixelBufferPixelFormatTypeKey): Int(kCVPixelFormatType_32BGRA),
-            String(kCVPixelBufferWidthKey): videoWidth,
-            String(kCVPixelBufferHeightKey): videoHeight,
+            String(kCVPixelBufferWidthKey): Int(pixelBufferWidth),
+            String(kCVPixelBufferHeightKey): Int(pixelBufferHeight),
             String(kCVPixelFormatOpenGLESCompatibility): kCFBooleanTrue
         ]
 


                        if let videoInput = self.assetWriterVideoInput {

                            self.assetWriterPixelBufferAdaptor = self.makePixelBufferAdaptor(assetWriterInput: videoInput, videoTrackSettings: videoTrackSettings)

                            if assetWriter.canAddInput(videoInput) {
                                assetWriter.addInput(videoInput)


                        success = assetWriterPixelBufferAdaptor.appendPixelBuffer(pixelBuffer, withPresentationTime: timeStamp)

//                        success = self.assetWriterVideoInput?.appendSampleBuffer(sampleBuffer)

                        self.delegate?.writerCoordinatorDidRecording(self, seconds: self.recordingSeconds)

                    } else {
