title: Video Capture Compressed with VTCompressionSession plays too fast
body: <p>I am receiving raw RGBA data from a AVCaptureVideoDataOutput and using VTCompressionSession to compress it to a raw H264 stream. </p>
  
  <p>The problem I have is that the resulting stream plays too fast (playing in VLC), about 3x the real speed.</p>
  
  <p>I am using the presentation times and durations from the captured data.  Using AVFileMovieOutput works correctly, but I want more control over the compression. </p>
  
  <p>I have tried setting kVTCompressionPropertyKey_ExpectedFrameRate but that makes no difference. </p>
  
  <pre><code>- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
     fromConnection:(AVCaptureConnection *)connection {
  
      CMTime presentationTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
      CMTime duration = CMSampleBufferGetDuration(sampleBuffer);
  
      CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
      CVPixelBufferLockBaseAddress(pixelBuffer, 0);
  
      OSStatus encodeStatus = VTCompressionSessionEncodeFrame(compressionSession, pixelBuffer, presentationTime, duration, NULL, NULL, NULL);
      if (encodeStatus != noErr) {
          NSLog(@"Encode error.");
      }
  
     CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
  }
  </code></pre>