【发布时间】:2016-05-13 18:49:14
【问题描述】:
我从 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);
}
【问题讨论】:
-
我觉得没问题。 IIRC 压缩触发回调,您可以使用该回调将帧添加到电影中。该回调中的 CMTime 怎么样?
标签: ios macos cocoa video toolbox