2
votes

I'm working on a video capture app using the AVFoundation framework, based on the AVCam sample by Apple. I'd like to implement functionality to set a maximum video length, and have the capture automatically stops when this limit is reached (similar to UIImagePickerController.videoMaximumDuration).

I'm assuming I need to register for some notification as the capture is recording, and to check the timestamp in this callback. I looked through the AV Foundation Programming Guide and did a bit of Googling, and I can't find a way to retrieve the elapsed time of a AVCaptureSession, AVCaptureMovieFileOutput, or AVCaptureSomethingElse.

Any insight would help. Thanks!

1
Have you looked at the presentation time stamp of the incoming CMSampleBuffers? Oh wait, you don't say how you're capturing. Are you using AVCaptureMovieFileOutput or AVCaptureVideoDataOutput? - Rhythmic Fistman

1 Answers

1
votes

You can set the maxRecordedDuration or maxRecordedFileSize. However, you need to make sure you handle the error correctly on the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error: delegate call to detect whether the recording stopped due to an error or due to reaching max duration/file size.

check the error code like:

if (([error code] == AVErrorMaximumDurationReached)) {
    [delegate captureSessionMaxDurationReached];
}