Class

AVAssetWriterInput

A writer used to append media samples to a single track of an asset writer's output file.

Declaration

@interface AVAssetWriterInput : NSObject

Overview

An AVAssetWriterInput object can append media samples packaged as CMSampleBufferRef objects, or collections of metadata, to a single track of the output file of an AVAssetWriter object.

When there are multiple inputs, AVAssetWriter tries to write media data in an ideal interleaving pattern for efficiency in storage and playback. Each of its inputs signals its readiness to receive media data for writing according to that pattern via the value of readyForMoreMediaData. If readyForMoreMediaData is YES, an input can accept additional media data while maintaining appropriate interleaving. You can only append media data to an input while its readyForMoreMediaData property is YES.

  • If you’re writing media data from a non-real-time source, such as an instance of AVAssetReader, you should hold off on generating or obtaining more media data to append to an input when the value of readyForMoreMediaData is NO. To help with control of the supply of non-real-time media data, you can use requestMediaDataWhenReadyOnQueue:usingBlock: to specify a block that the input should invoke whenever it’s ready to append input.

  • If you’re writing media data from a real-time source such as an AVCaptureOutput object, you should set the input’s expectsMediaDataInRealTime property to YES to ensure to calculate the value of readyForMoreMediaData appropriately. When expectsMediaDataInRealTime is YES, readyForMoreMediaData will become NO only when the input cannot process media samples as quickly as they are provided by the client. If readyForMoreMediaData becomes NO for a real-time source, the client may need to drop samples or consider reducing the data rate of appended samples.

The value of readyForMoreMediaData will often change from NO to YES asynchronously while processing and writing previously-supplied media data to the output. It is possible for all of an asset writer’s inputs temporarily to return NO for readyForMoreMediaData.

Topics

Creating an Asset Writer Input Instance

+ assetWriterInputWithMediaType:outputSettings:

Returns a new writer input object initialized with the specified media type and output settings.

+ assetWriterInputWithMediaType:outputSettings:sourceFormatHint:

Returns a new writer input object initialized with the specified media type, output settings, and source format hint.

- initWithMediaType:outputSettings:

Initialize a writer input object with the specified media type and output settings.

- initWithMediaType:outputSettings:sourceFormatHint:

Initialize a writer input object with the specified media type, output settings, and source hint.

Video Settings Dictionaries

Define output image and video formats by using the key and value constants.

Adding Media Samples

- appendSampleBuffer:

Appends samples to the receiver.

readyForMoreMediaData

A Boolean value that indicates the readiness of the input to accept more media data.

- markAsFinished

Tells the writer it can't append more buffers to this input.

- requestMediaDataWhenReadyOnQueue:usingBlock:

Instructs the receiver to invoke a block repeatedly, at its convenience, to gather media data for writing to the output.

Configuring a Writer Input

metadata

The collection of track-level metadata to associate with the asset and for carriage in the output file.

transform

The transform specified in the output file as the preferred transformation of the visual media data for display purposes.

mediaTimeScale

Specifies the media time scale to be used.

expectsMediaDataInRealTime

A Boolean value that indicates whether the input should tailor its processing of media data for real-time sources.

marksOutputTrackAsEnabled

Returns whether the receiver’s track is enabled.

naturalSize

Size specified in the output file as the natural dimensions of the visual media data for display.

preferredVolume

The preferred volume level for storing in the output file.

Managing Track Associations

- addTrackAssociationWithTrackOfInput:type:

Associates the track corresponding to the specified input with the track corresponding with the receiver.

- canAddTrackAssociationWithTrackOfInput:type:

Validates the association between the tracks and their corresponding pair of inputs.

Inspecting a Writer Input

mediaType

The media type of the samples that are appendable to the input.

outputSettings

The settings used for encoding the media appended to the output.

sourceFormatHint

A hint about the format of the buffers to appended.

sampleReferenceBaseURL

The base URL sample references are relative to.

Managing Language Settings

extendedLanguageTag

Language tag to associate with the track corresponding to the receiver

languageCode

Language to associate with the track corresponding to the receiver.

Performing Multiple-Pass Encoding

canPerformMultiplePasses

A Boolean value that indicates whether the input might perform multiple passes over appended media data.

currentPassDescription

An object that describes the requirements, such as source time ranges to append or re-append, to the current pass.

- markCurrentPassAsFinished

Instructs the receiver to analyze the appended media data and determine whether to improve the results by re-encoding certain segments.

performsMultiPassEncodingIfSupported

A Boolean value that indicates whether the input should attempt to encode the source media data using multiple passes.

preferredMediaChunkAlignment

The boundary, in bytes, for aligning media chunks.

preferredMediaChunkDuration

The duration used for each chunk of sample data in the output file.

- respondToEachPassDescriptionOnQueue:usingBlock:

Instructs the receiver to invoke a client-supplied block whenever a new pass has begun.

Specifying Media Data Layout

mediaDataLocation

Specifies where to lay out the media data and whether to interleave the media data as the main media data.

AVAssetWriterInputMediaDataLocation

A value indicating how to lay out different media data and whether to interleave that media data.

Relationships

Inherits From

See Also

File Export

Exporting Video to Alternative Formats

Convert an existing movie file to a different format.

AVAssetExportSession

An object that transcodes the contents of an asset source object to create an output of the form described by a specified export preset.

AVAssetWriter

An object used to write media data to a new file of a specified audiovisual container type.

AVVideoTransferFunction_ITU_R_2100_HLG

The transfer function for the ITU_R BT.2100 color space.

AVOutputSettingsAssistant

An object that specifies a set of parameters for configuring objects that use output settings dictionaries.

AVAssetWriterInputGroup

A group of tracks in a mutually exclusive relationship.

AVAssetWriterInputMetadataAdaptor

An object that defines an interface for writing metadata packaged as timed metadata groups into a single asset writer input.

AVAssetWriterInputPassDescription

An object that defines an interface for querying about the requirements of the current pass.

AVAssetWriterInputPixelBufferAdaptor

A buffer used to append video samples packaged as pixel buffers to a single asset writer input.