【问题标题】:Video Capture Compressed with VTCompressionSession plays too fast使用 VTCompressionSession 压缩的视频捕获播放速度过快
【发布时间】: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


【解决方案1】:

我是:

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

还有。你如何启动你的压缩会话?你设置了哪些“k”参数?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 2020-06-28
    • 2023-03-09
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多