如何查找使用AVCaptureVideoDataOutput录制的视频的持续时间

时间:2016-06-16 13:48:27

标签: ios objective-c xcode avfoundation

如果我们使用AVCaptureMovieFileOutput,我们会在其上设置recordedDuration属性,以显示录制视频的长度。

但是我找不到与使用AVCaptureVideoDataOutput录制的视频相似的内容。

1 个答案:

答案 0 :(得分:1)

如果您正在使用AVCaptureVideoDataOutput,那么请在您的委托回调中

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;

您可以通过记录您记录的第一个和最后一个sampleBuffer的演示时间戳来计算记录的持续时间:

CMTime start = CMSampleBufferGetPresentationTimeStamp(sampleBufferFirst);
CMTime end = CMSampleBufferGetPresentationTimeStamp(sampleBufferLast);

CMTime recordedDuration = CMTimeSubtract(end, start);