4

我有一个视频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;  

我在正确的轨道上吗?

4

2 回答 2

2

在定义的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 );

"

于 2016-01-21T18:15:10.243 回答
0

迪克森迅速回答:

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)
于 2018-11-09T11:54:56.280 回答