                 }
 
                 let metadata = CMCopyDictionaryOfAttachments(allocator: nil, target: imageDataBuffer, attachmentMode: kCMAttachmentMode_ShouldPropagate) as? [String: Any]
-                let mirrored = self.isMirroredImageIfFrontCamera && captureImageConnection.isFrontCameraDevice
+                let mirrored = self.isMirroredImageIfFrontCamera && stillImageOutputCaptureConnection.isFrontCameraDevice
                 let image = mirrored ? scaledImage.mirrored : scaledImage
                 onMainThreadAsync {
                     completion(image, metadata)

        if let c = self.captureVideoPreviewView, c.session != nil {
            c.session = nil
        }
        sessionQueue.async {
            captureVideoPreviewView.session = self.captureSession
        }
        self.captureVideoPreviewView = captureVideoPreviewView
    }


            } else {
                videoOrientation = .portrait
            }
            stillImageOutputCaptureConnection.videoOrientation = videoOrientation
            self.captureSession.commitConfiguration() // defer より前のタイミングで commit したい

            self.stillImageOutput.captureStillImageAsynchronously(from: stillImageOutputCaptureConnection) { (imageDataBuffer, error) -> Void in
                guard let imageDataBuffer = imageDataBuffer, let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataBuffer) else {
                    onMainThreadAsync {
                        completion(nil, nil)
