我从AVCaptureVideoDataOutput接收原始RGBA数据,并使用VTCompressionSession将其压缩为原始H264流。
我遇到的问题是结果流播放得太快(在VLC中播放),大约是实际速度的3倍。
我正在使用捕获数据中的演示时间和持续时间。使用AVFileMovieOutput正常工作,但我希望更多地控制压缩。
我尝试过设置kVTCompressionPropertyKey_ExpectedFrameRate,但没有区别。
- (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);
}
答案 0 :(得分:0)
我:
CFAbsoluteTime currentTime = CFAbsoluteTimeGetCurrent();
CMTime presentationTimeStamp = CMTimeMake(currentTime*27000000, 27000000);
VTCompressionSessionEncodeFrame(_enc_session, imageBuffer, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, NULL);
另外。你如何初始化压缩会话?您设置了什么'k'参数?