Tom
Tom

Reputation: 336

How to find duration of video recorded with AVCaptureVideoDataOutput

If we use AVCaptureMovieFileOutput, we have recordedDuration property on it that gives the length of the video recorded.

However I couldn't find anything similar for video recorded using AVCaptureVideoDataOutput.

Upvotes: 1

Views: 415

Answers (1)

Gordon Childs
Gordon Childs

Reputation: 36169

If you're using AVCaptureVideoDataOutput then in your delegate callback

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

you can calculate the recorded duration by noting the presentation time stamps of the first and last sampleBuffers that you record:

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

CMTime recordedDuration = CMTimeSubtract(end, start);

Upvotes: 2

Related Questions