iOS Developer Library

Developer

AVFoundation Framework Reference AVAssetReaderOutput Class Reference

Options
Deployment Target:

On This Page
Language:

AVAssetReaderOutput

AVAssetReaderOutput is an abstract class that defines an interface for reading a single collection of samples of a common media type from an AVAssetReader object.

There are several subclasses of AVAssetReaderOutput for specific tasks, such as AVAssetReaderTrackOutput or AVAssetReaderVideoCompositionOutput.

You can read the media data of an asset by adding one or more concrete instances of AVAssetReaderOutput to an AVAssetReader object using addOutput:.

Conforms To


Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

Availability


Available in iOS 4.1 and later.
  • Synchronously copies the next sample buffer for the output.

    Declaration

    Swift

    func copyNextSampleBuffer() -> CMSampleBuffer!

    Objective-C

    - (CMSampleBufferRef)copyNextSampleBuffer

    Return Value

    The output sample buffer, or NULL if there are no more sample buffers available for the output within the time range specified by the asset reader’s timeRange property. Ownership follows the The Create Rule.

    Discussion

    If this method returns NULL, you should check the value of the associated AVAssetReader object’s status property to determine why no more samples could be read.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.1 and later.

  • Indicates whether the data in buffers gets copied before being vended.

    Declaration

    Swift

    var alwaysCopiesSampleData: Bool

    Objective-C

    @property(nonatomic) BOOL alwaysCopiesSampleData

    Discussion

    When the value of this property is YEStrue, the output always vends a buffer with copied data—you can freely modify data in such buffers.

    When the value of this property is NOfalse, the buffers vended may not be copied—such buffers may still be referenced by other entities. The result of modifying a buffer whose data hasn't been copied is undefined.

    Requesting buffers whose data hasn’t been copied when possible can lead to performance improvements.

    The default value of this property is YEStrue

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 5.0 and later.

  • mediaType mediaType Property

    A string representing the media type of the track (or tracks) represented by the output. (read-only)

    Declaration

    Swift

    var mediaType: String! { get }

    Objective-C

    @property(nonatomic, readonly) NSString *mediaType

    Discussion

    The value of this property is one of the media type strings defined in AVMediaFormat.h.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.1 and later.

  • Informs the receiver that no more reconfiguration of time ranges is necessary and allows the attached AVAssetReader to advance to AVAssetReaderStatusCompleted.

    Declaration

    Swift

    func markConfigurationAsFinal()

    Objective-C

    - (void)markConfigurationAsFinal

    Discussion

    When the value of supportsRandomAccess is YEStrue, the attached asset reader will not advance to AVAssetReaderStatusCompleted until this method is called.

    When the destination of media data vended by the receiver is an AVAssetWriterInput configured for multi-pass encoding, a convenient time to invoke this method is after the asset writer input indicates that no more passes will be performed.

    Once this method has been called, further invocations of resetForReadingTimeRanges: are disallowed.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 8.0 and later.

  • Restarts reading with a new set of time ranges.

    Declaration

    Swift

    func resetForReadingTimeRanges(_ timeRanges: [AnyObject]!)

    Objective-C

    - (void)resetForReadingTimeRanges:(NSArray *)timeRanges

    Parameters

    timeRanges

    An array of NSValue objects, each representing a single CMTimeRange structure.

    Discussion

    This method may only be used if supportsRandomAccess has been set to YEStrue and may not be called after markConfigurationAsFinal has been invoked.

    This method is often used in conjunction with AVAssetWriter multi-pass. When used as such, the caller invokes copyNextSampleBuffer until that method returns NULL and then asks the AVAssetWriterInput for a set of time ranges from which it is believed that media data should be re-encoded. These time ranges are then passed to this method to set up the asset reader output for the next pass.

    The time ranges set here override the time range set on AVAssetReader instance’s timeRange property. Just as with that property, for each time range in the array the intersection of that time range and CMTimeRangeMake(kCMTimeZero, asset.duration) will take effect. If the start times of each time range in the array are not strictly increasing or if two or more time ranges in the array overlap, an NSInvalidArgumentException will be raised. It is an error to include a time range with a non-numeric start time or duration (CMTIME_IS_NUMERIC), unless the duration is kCMTimePositiveInfinity.

    If this method is invoked after the status of the attached AVAssetReader instance has become AVAssetReaderStatusFailed or AVAssetReaderStatusCancelled, no change in status will occur and the result of the next call to copyNextSampleBuffer will be NULL.

    If this method is invoked before all media data has been read, for example, copyNextSampleBuffer has not yet returned NULL, an exception is thrown. This method may not be called before startReading has been invoked on the attached asset reader.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value that indicates whether the asset reader output supports reconfiguration of the time ranges to read.

    Declaration

    Swift

    var supportsRandomAccess: Bool

    Objective-C

    @property(nonatomic) BOOL supportsRandomAccess

    Discussion

    When the value of this property is YEStrue, the time ranges read by the asset reader output can be reconfigured during reading using the resetForReadingTimeRanges: method. This also prevents the attached AVAssetReader instance from progressing to AVAssetReaderStatusCompleted until markConfigurationAsFinal has been invoked.

    The default value is NOfalse, which means that the asset reader output may not be reconfigured once reading has begin. When the value of this property is NOfalse, the AVAssetReader instance may be able to read media data more efficiently, particularly when multiple asset reader outputs are attached.

    This property may not be set after startReading has been called on the attached asset reader.

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 8.0 and later.