AVCaptureFileOutput Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AVFoundation.framework
Availability
Available in iOS 4.0 and later.
Declared in
AVCaptureOutput.h

Overview

AVCaptureFileOutput is an abstract sub-class of AVCaptureOutput that describes a file output destination to an AVCaptureSession. For example, you use an instance of its concrete subclass, AVCaptureMovieFileOutput, to save capture output to a QuickTime movie file. The concrete subclasses of AVCaptureFileOutput are AVCaptureMovieFileOutput, which records media to a QuickTime movie file, and AVCaptureAudioFileOutput, which writes audio media to a variety of audio file formats.

This abstract superclass defines the interface for outputs that record media samples to files. File outputs can start recording to a new file using startRecordingToOutputFileURL:recordingDelegate: method.

In OS X, on successive invocations of this method the output file can be changed dynamically without losing media samples. A file output can stop recording using the stopRecording method. Because files are recorded in the background, you need to specify a delegate for each new file to be notified when recorded files are finished.

In OS X, you can also set a delegate on the file output itself that can be used to control recording along exact media sample boundaries using the captureOutput:didOutputSampleBuffer:fromConnection:: method.

Tasks

Managing Recording

Configuration

Information About Output

Properties

maxRecordedDuration

The longest duration allowed for the recording.

@property(nonatomic) CMTime maxRecordedDuration
Discussion

This property specifies a hard limit on the duration of recorded files. Recording is stopped when the limit is reached and the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error: delegate method is invoked with an appropriate error. The default value of this property is kCMTimeInvalid, which indicates no limit.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

maxRecordedFileSize

The maximum size, in bytes, of the data that should be recorded by the receiver.

@property(nonatomic) int64_t maxRecordedFileSize
Discussion

This property specifies a hard limit on the data size of recorded files. Recording is stopped when the limit is reached and the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error: delegate method is invoked with an appropriate error. The default value of this property is 0, which indicates no limit.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

minFreeDiskSpaceLimit

The minimum amount of free space, in bytes, required for recording to continue on a given volume.

@property(nonatomic) int64_t minFreeDiskSpaceLimit
Discussion

This property specifies a hard lower limit on the amount of free space that must remain on a target volume for recording to continue. Recording is stopped when the limit is reached and the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error: delegate method is invoked with an appropriate error.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

outputFileURL

The URL to which output is directed. (read-only)

@property(nonatomic, readonly) NSURL *outputFileURL
Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

recordedDuration

Indicates the duration of the media recorded to the current output file. (read-only)

@property(nonatomic, readonly) CMTime recordedDuration
Discussion

If recording is in progress, this property returns the total time recorded so far.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

recordedFileSize

Indicates the size, in bytes, of the data recorded to the current output file. (read-only)

@property(nonatomic, readonly) int64_t recordedFileSize
Discussion

If a recording is in progress, this property returns the size in bytes of the data recorded so far.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

recording

Indicates whether recording is in progress.

@property(nonatomic, readonly, getter=isRecording) BOOL recording
Discussion

The value of this property is YES when the file output currently has a file to which it is writing new samples, NO otherwise.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

Instance Methods

startRecordingToOutputFileURL:recordingDelegate:

Starts recording to a given URL.

- (void)startRecordingToOutputFileURL:(NSURL *)outputFileURL recordingDelegate:(id < AVCaptureFileOutputRecordingDelegate >)delegate
Parameters
outputFileURL

An NSURL object containing the URL of the output file.

This method throws an NSInvalidArgumentException if the URL is not a valid file URL.

delegate

A object to serve as delegate for the recording session.

Discussion

The method sets the file URL to which the receiver is currently writing output media. If a file at the given URL already exists when capturing starts, recording to the new file will fail.

In OS X, you do not need to call stopRecording before calling this method while another recording is in progress. If this method is invoked while an existing output file was already being recorded, no media samples will be discarded between the old file and the new file.

In iOS, this frame accurate file switching is not supported. You must call stopRecording before calling this method again to avoid any errors.

When recording is stopped either by calling stopRecording, by changing files using this method, or because of an error, the remaining data that needs to be included to the file will be written in the background. Therefore, you must specify a delegate that will be notified when all data has been written to the file using the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error: method. The recording delegate can also optionally implement methods that inform it when data starts being written, when recording is paused and resumed, and when recording is about to be finished.

In OS X, if this method is called within the captureOutput:didOutputSampleBuffer:fromConnection: delegate method, the first samples written to the new file are guaranteed to be those contained in the sample buffer passed to that method.

Note: AVCaptureAudioFileOutput does not support startRecordingToOutputFileURL:recordingDelegate:. Use startRecordingToOutputFileURL:outputFileType:recordingDelegate: instead.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h

stopRecording

Tells the receiver to stop recording to the current file.

- (void)stopRecording
Discussion

You can call this method when they want to stop recording new samples to the current file, and do not want to continue recording to another file. If you want to switch from one file to another, you should not call this method. Instead you should simply call startRecordingToOutputFileURL:recordingDelegate: with the new file URL.

When recording is stopped either by calling this method, by changing files using startRecordingToOutputFileURL:recordingDelegate:, or because of an error, the remaining data that needs to be included to the file will be written in the background. Therefore, before using the file, you must wait until the delegate that was specified in startRecordingToOutputFileURL:recordingDelegate: is notified when all data has been written to the file using the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error: method.

In OS X, if this method is called within the captureOutput:didOutputSampleBuffer:fromConnection: delegate method, the last samples written to the current file are guaranteed to be those that were output immediately before those in the sample buffer passed to that method.

Availability
  • Available in iOS 4.0 and later.
Declared In
AVCaptureOutput.h