iOS Developer Library

Developer

AVFoundation Framework Reference AVCaptureFileOutput Class Reference

Options
Deployment Target:

On This Page
Language:

AVCaptureFileOutput

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.

Conforms To


Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 4.0 and later.
  • Starts recording to a given URL.

    Declaration

    Swift

    func startRecordingToOutputFileURL(_ outputFileURL: NSURL!, recordingDelegate delegate: AVCaptureFileOutputRecordingDelegate!)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

  • Tells the receiver to stop recording to the current file.

    Declaration

    Swift

    func stopRecording()

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

    See Also

    recording

  • recording recording Property

    Indicates whether recording is in progress.

    Declaration

    Swift

    var recording: Bool { get }

    Objective-C

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

    Discussion

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

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

  • The longest duration allowed for the recording.

    Declaration

    Swift

    var maxRecordedDuration: CMTime

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var maxRecordedFileSize: Int64

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var minFreeDiskSpaceLimit: Int64

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var outputFileURL: NSURL! { get }

    Objective-C

    @property(nonatomic, readonly) NSURL *outputFileURL

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var recordedDuration: CMTime { get }

    Objective-C

    @property(nonatomic, readonly) CMTime recordedDuration

    Discussion

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

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    var recordedFileSize: Int64 { get }

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.