2016-01-21 180 views
4

我有一个视频AVCaptureDeviceAVMediaTypeVideo),我正在使用setExposureTargetBias:completionHandler短暂减少曝光,然后再次恢复。 我需要知道captureOutput:didOutputSampleBuffer:fromConnection:中的哪个缓冲区对应于曝光量减少的第一帧。AVCaptureDevice:比较采样缓冲时间戳

的文档说:

块接收该匹配所述第一缓冲器的所述设置已被应用到的时间戳。时间戳与设备时钟同步,因此必须在与通过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; 

我在正确的轨道上?

回答

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);