title: Using AVCaptureVideoDataOutput and AVCaptureAudioDataOutput
body: <p>I have an AVCaptureVideoDataOutput session running set up as below, which works great and records the buffer to a file.</p>
  
  <p>I want to also record the audio but there doesn't seem to be any in the buffer even though I've added the microphone as an input to the captureSession.</p>
  
  <p>I suspect I need to also use AVCaptureAudioDataOutput.</p>
  
  <pre><code>func setupCaptureSession()
  {
  captureSession.beginConfiguration()
  captureSession.sessionPreset = AVCaptureSessionPreset1280x720
  videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "sample 
  buffer delegate", attributes: []))
  
  
  videoOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString) : NSNumber(value: kCVPixelFormatType_32BGRA as UInt32)]
  
  videoOutput.alwaysDiscardsLateVideoFrames = true
  
  captureSession.addOutput(videoOutput)
  
  captureSession.addInput(deviceInputFromDevice(backCameraDevice))
  
  captureSession.addInput(deviceInputFromDevice(micDevice))
  
  captureSession.commitConfiguration()
  captureSession.startRunning()
  }
  </code></pre>
  
  <p>and then here's how I get the video buffer and send it off to be written to a file</p>
  
  <pre><code>func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!)
  {
  
  writeVideoFromData(sampleBuffer) // a function that writes the buffer to disk
  
  }
  </code></pre>