如果我们使用AVCaptureMovieFileOutput
,我们会在其上设置recordedDuration
属性,以显示录制视频的长度。
但是我找不到与使用AVCaptureVideoDataOutput
录制的视频相似的内容。
答案 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);