【问题标题】:AVCaptureDevice: comparing samplebuffer timestampsAVCaptureDevice:比较样本缓冲区时间戳
【发布时间】:2016-01-21 12:56:54
【问题描述】:

我有一个视频AVCaptureDevice (AVMediaTypeVideo),正在使用setExposureTargetBias:completionHandler 短暂减少曝光,然后再次恢复它。 我需要确切知道captureOutput:didOutputSampleBuffer:fromConnection: 中的哪个缓冲区对应于曝光减少的第一帧。

文档说:

该块收到一个时间戳,该时间戳与已应用该设置的第一个缓冲区的时间戳相匹配。时间戳与设备时钟同步,因此必须先转换为主时钟,然后再与通过 AVCaptureVideoDataOutput 实例传递的缓冲区的时间戳进行比较。

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/#//apple_ref/occ/instm/AVCaptureDevice/setExposureTargetBias:completionHandler:

如何获取“设备时钟”? 我在completionHandler中做了以下操作,虽然主机时钟似乎与主时钟重合。

CMClockRef masterClock = self.captureSession.masterClock;  
CMClockRef deviceClock = CMClockGetHostTimeClock();  
syncTimeConverted = CMSyncConvertTime( syncTime, deviceClock, masterClock );

我打算在captureOutput:didOutputSampleBuffer:fromConnection: 中执行以下操作来测试缓冲区是否是我想要的缓冲区

CMTime bufferTime = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );  
bool isDroppedExposureFrame = CMTimeCompare( bufferTime, syncTimeConverted ) == 0;  

我走对了吗?

【问题讨论】:

    标签: ios avcapturesession avcapturedevice cmtime


    【解决方案1】:

    AVCaptureSession.h 中定义了CMClockRef masterClock,我找到了一个相反的解决方案:

    "

    例如,如果要将输出时间戳反向同步到原始时间戳,可以执行以下操作:

    captureOutput:didOutputSampleBuffer:fromConnection:

    AVCaptureInputPort *port = [[connection inputPorts] objectAtIndex:0];
    CMClockRef originalClock = [port clock];
    CMTime syncedPTS = CMSampleBufferGetPresentationTime( sampleBuffer );
    CMTime originalPTS = CMSyncConvertTime( syncedPTS, [session masterClock], originalClock );
    

    "

    【讨论】:

      【解决方案2】:

      迪克森的快速回答:

      func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
      
              let port = connection.inputPorts[0]
              let originalClock = port.clock
              let syncedPTS = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
              let originalPTS = CMSyncConvertTime( syncedPTS, from: session.masterClock!, to: originalClock!)
              let result = CMTimeCompare(originalPTS, self.timeStampOfFirstMatchinBuffer)
              switch result {
              case 0:
                  print("Timing match!")
              default:
                  return
              }
          }
      

      其中timeStampOfFirstMatchinBuffer 是你设置时得到的CMTime 值

      setExposureTargetBias(_ bias: Float, 
               completionHandler handler: ((CMTime) -> Void)? = nil)
      

      【讨论】:

        猜你喜欢
        • 2020-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-09
        相关资源
        最近更新 更多