3

I am receiving raw RGBA data from a AVCaptureVideoDataOutput and using VTCompressionSession to compress it to a raw H264 stream.

The problem I have is that the resulting stream plays too fast (playing in VLC), about 3x the real speed.

I am using the presentation times and durations from the captured data. Using AVFileMovieOutput works correctly, but I want more control over the compression.

I have tried setting kVTCompressionPropertyKey_ExpectedFrameRate but that makes no difference.

- (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);
}
  • It seems alright to me. IIRC the compression triggers a callback that you use to add the frames to your film. How are the CMTime in that callback? –  Feb 04 '16 at 09:08

1 Answers1

0

I'm:

CFAbsoluteTime currentTime = CFAbsoluteTimeGetCurrent();
CMTime presentationTimeStamp = CMTimeMake(currentTime*27000000, 27000000);
VTCompressionSessionEncodeFrame(_enc_session, imageBuffer, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, NULL);

Also. How do you init your compression session? What 'k' parameters do you set to what?

Anders Cedronius
  • 2,036
  • 1
  • 23
  • 29