Class: AVAssetWriterInput

Inherits:
NSObject show all

Overview

You use an AVAssetWriterInput to append media samples packaged as CMSampleBuffer objects (see CMSampleBufferRef), or collections of metadata, to a single track of the output file of an AVAssetWriter object.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (Boolean) expectsMediaDataInRealTime

Indicates whether the input should tailor its processing of media data for real-time sources. If you are appending media data to an input from a real-time source, such as an AVCaptureOutput, you should set expectsMediaDataInRealTime to YES. This will ensure that readyForMoreMediaData is calculated appropriately for real-time usage.You cannot set this property after writing has started.

Returns:

  • (Boolean)

- (CMTimeScale) mediaTimeScale

Specifies the media time scale to be used For file types that support media time scales, such as QuickTime Movie files, specifies the media time scale to be used. The default value of this property is 0, which indicates that the writer input object should choose an appropriate value.It is an error to assign a value other than 0 to this property if the object’s mediaType property is set to to AVMediaTypeAudio. You cannot set this property after writing has started.

Returns:

  • (CMTimeScale)

- (String) mediaType (readonly)

The media type of the samples that can be appended to the input. (read-only) The value of this property is one of the media type strings defined in AV Foundation Constants Reference.

Returns:

- (Array) metadata

The collection of track-level metadata for association with the asset and for carriage in the output file. The array contains AVMetadataItem objects representing the collection of track-level metadata to be written in the output file.You cannot set this property after writing has started.

Returns:

- (Hash) outputSettings (readonly)

The settings used for encoding the media appended to the output. (read-only) A value of nil specifies that appended samples should not be re-encoded.

Returns:

- (Boolean) readyForMoreMediaData (readonly)

Indicates the readiness of the input to accept more media data. (read-only) This property is observable using key-value observing (see Key-Value Observing Programming Guide). Observers should not assume that they will be notified of changes on a specific thread.

Returns:

  • (Boolean)

- (__attribute__((NSObject)) CMFormatDescriptionRef) sourceFormatHint (readonly)

A hint about the format of buffers that will be appended. (read-only) An AVAssetWriterInput object may be able to use this hint to fill in missing output settings or perform more upfront validation. To guarantee successful file writing, if you set this property you should ensure that subsequently-appended buffers are of the specified format. An NSInvalidArgumentException will be thrown if the media type of the format description does not match the media type of the writer input.

Returns:

  • (__attribute__((NSObject)) CMFormatDescriptionRef)

- (CGAffineTransform) transform

The transform specified in the output file as the preferred transformation of the visual media data for display purposes. If no value is specified, the identity transform is used.

Returns:

Class Method Details

+ (AVAssetWriterInput) assetWriterInputWithMediaType(mediaType, outputSettings:outputSettings)

Returns a new writer input object initialized with the specified media type and output settings. Each new input accepts data for a new track of the asset writer’s output file. You add an input to an asset writer using the AVAssetWriter method addInput:.Passing nil for outputSettings instructs the input to pass through appended samples, doing no processing before they are written to the output file. This is useful if, for example, you are appending buffers that are already in a desirable compressed format. However, passthrough is currently supported only when writing to QuickTime Movie files (i.e. the AVAssetWriter was initialized with AVFileTypeQuickTimeMovie). For other file types, you must specify non-nil output settings.

Parameters:

  • mediaType (String)

    The type of samples to be accepted by the input object. For a list of media types, see AV Foundation Constants Reference.

  • outputSettings (Hash)

    The settings used for encoding the media appended to the output. Pass nil to specify that the appended samples should not be re-encoded.Audio output settings keys are defined in AV Foundation Audio Settings Constants. Video output settings keys are defined in AV Foundation Constants Reference. Video output settings with keys from are not currently supported.

Returns:

  • (AVAssetWriterInput)

    A new writer input object that can accept samples of the specified media type and write them to the output file.

+ (AVAssetWriterInput) assetWriterInputWithMediaType(mediaType, outputSettings:outputSettings, sourceFormatHint:sourceFormatHint)

Returns a new writer input object initialized with the specified media type, output settings, and source format hint. Each new input accepts data for a new track of the asset writer’s output file. You add an input to an asset writer using the AVAssetWriter method addInput:.Passing nil for outputSettings instructs the input to pass through appended samples, doing no processing before they are written to the output file. This is useful if, for example, you are appending buffers that are already in a desirable compressed format. However, passthrough is currently supported only when writing to QuickTime Movie files (i.e. the AVAssetWriter was initialized with AVFileTypeQuickTimeMovie). For other file types, you must specify non-nil output settings.

Parameters:

  • mediaType (String)

    The media type of the samples to be accepted by the input object. For a list of media types, see AV Foundation Constants Reference.

  • outputSettings (Hash)

    Specify a dictionary containing the settings used for encoding the media appended to the output. You may pass nil if you do not want the appended samples to be re-encoded.Audio output settings keys are defined in AV Foundation Audio Settings Constants. Video output settings keys are defined in AV Foundation Constants Reference. Video output settings with keys from are not currently supported.

  • sourceFormatHint (CMFormatDescriptionRef)

    This parameter contains a hint of the type of the format buffers to be appended. If you specify a value for this parameter, the writer input object may be able to fill in missing output settings or perform more upfront validation. If you specify a value for this property, you should make sure that the buffers you append are of the indicated type.

Returns:

  • (AVAssetWriterInput)

    A new writer input object that can accept samples of the specified media type and write them to the output file.

Instance Method Details

- (Boolean) appendSampleBuffer(sampleBuffer)

Appends samples to the receiver.

The timing information in the sample buffer, considered relative to the time passed to the asset writer’s startSessionAtSourceTime: will be used to determine the timing of those samples in the output file.Do not modify sampleBuffer or its contents after you have passed it to this method.

Parameters:

  • sampleBuffer (CMSampleBufferRef)

    The CMSampleBuffer to be appended.

Returns:

  • (Boolean)

    YES if sampleBuffer as appended successfully, otherwise NO.

- (Object) initWithMediaType(mediaType, outputSettings:outputSettings)

Initialize a writer input object with the specified media type and output settings. Each new input accepts data for a new track of the asset writer’s output file. You add an input to an asset writer using the AVAssetWriter method addInput:.Passing nil for outputSettings instructs the input to pass through appended samples, doing no processing before they are written to the output file. This is useful if, for example, you are appending buffers that are already in a desirable compressed format. However, passthrough is currently supported only when writing to QuickTime Movie files (i.e. the AVAssetWriter was initialized with AVFileTypeQuickTimeMovie). For other file types, you must specify non-nil output settings.When the mediaType parameter is AVMediaTypeAudio, the outputSettings dictionary does not support the AVEncoderAudioQualityKey and AVSampleRateConverterAudioQualityKey keys. When using this method, an audio settings dictionary must be fully specified, meaning that it must contain the AVFormatIDKey, AVSampleRateKey, and AVNumberOfChannelsKey keys. If no other channel layout information is available, a value of 1 for the AVNumberOfChannelsKey key results in mono output and a value of 2 results in stereo output. If the AVNumberOfChannelsKey key specifies a value greater than 2, the dictionary must also specify a value for the AVChannelLayoutKey key. For audio using the kAudioFormatLinearPCM format, include all relevant AVLinearPCM*Key keys. For the kAudioFormatAppleLossless format, include the AVEncoderBitDepthHintKey keys. To avoid specifying values for each of those keys, use the initWithMediaType:outputSettings:sourceFormatHint: method instead.When the mediaType parameter is AVMediaTypeVideo, the outputSettings dictionary must request a compressed video format. This means that the values specified in the dictionary must follow the rules for compressed video output, as described in AVVideoSettings.h. When using this initializer, a video settings dictionary must be fully specified, meaning that it must contain the following keys: AVVideoCodecKey, AVVideoWidthKey, and AVVideoHeightKey. To avoid specifying values for each of those keys, use the initWithMediaType:outputSettings:sourceFormatHint: method.Note: On iOS, the only values currently supported for the AVVideoCodecKey key are AVVideoCodecH264 and AVVideoCodecJPEG. The AVVideoCodecH264 value is not supported on iPhone 3G. For the AVVideoScalingModeKey key, the value AVVideoScalingModeFit value is not supported.

Parameters:

  • mediaType (String)

    The media type of the samples to be accepted by the input object. For a list of media types, see AV Foundation Constants Reference.

  • outputSettings (Hash)

    Specify a dictionary containing the settings used for encoding the media appended to the output. You may pass nil for this parameter if you do not want the appended samples to be re-encoded.Audio output settings keys are defined in AV Foundation Audio Settings Constants. Video output settings keys are defined in AV Foundation Constants Reference. Video output settings with keys from are not currently supported.

Returns:

  • (Object)

    An initialized writer input object that can accept samples of the specified media type and write them to the output file.

- (Object) initWithMediaType(mediaType, outputSettings:outputSettings, sourceFormatHint:sourceFormatHint)

Initialize a writer input object with the specified media type, output settings, and source hint. Each new input accepts data for a new track of the asset writer’s output file. You add an input to an asset writer using the AVAssetWriter method addInput:.Passing nil for outputSettings instructs the input to pass through appended samples, doing no processing before they are written to the output file. This is useful if, for example, you are appending buffers that are already in a desirable compressed format. However, passthrough is currently supported only when writing to QuickTime Movie files (i.e. the AVAssetWriter was initialized with AVFileTypeQuickTimeMovie). For other file types, you must specify non-nil output settings.

Parameters:

  • mediaType (String)

    The media type of the samples to be accepted by the input object. For a list of media types, see AV Foundation Constants Reference.

  • outputSettings (Hash)

    Specify a dictionary containing the settings used for encoding the media appended to the output. You may pass nil for this parameter if you do not want the appended samples to be re-encoded.Audio output settings keys are defined in AV Foundation Audio Settings Constants. Video output settings keys are defined in AV Foundation Constants Reference. Video output settings with keys from are not currently supported.

  • sourceFormatHint (CMFormatDescriptionRef)

    This parameter contains a hint of the type of the format buffers to be appended. If you specify a value for this parameter, the writer input object may be able to fill in missing output settings or perform more upfront validation. If you specify a value for this property, you should make sure that the buffers you append are of the indicated type.

Returns:

  • (Object)

    An initialized writer input object that can accept samples of the specified media type and write them to the output file.

- (Object) markAsFinished

Tells the writer that no more buffers will be appended to this input. If you are monitoring each input's expectsMediaDataInRealTime value to keep the output file well interleaved, it is important to call this method when you have finished adding buffers to a track. This is necessary to prevent other inputs from stalling, as they may otherwise wait forever for that input's media data, attempting to complete the ideal interleaving pattern.

Returns:

- (Object) requestMediaDataWhenReadyOnQueue(queue, usingBlock:block)

Instructs the receiver to invoke a block repeatedly, at its convenience, in order to gather media data for writing to the output. The block should append media data to the input either until the input’s readyForMoreMediaData property becomes NO or until there is no more media data to supply (at which point it may choose to mark the input as finished using markAsFinished). The block should then exit. After the block exits, if the input has not been marked as finished, once the input has processed the media data it has received and becomes ready for more media data again, it will invoke the block again in order to obtain more.A typical use of this method, with a block that supplies media data to an input while respecting the input’s readyForMoreMediaData property, might look like this:You should not use this method with a push-style buffer source, such as AVCaptureAudioDataOutput or AVCaptureVideoDataOutput, because such a combination will typically require intermediate queueing of buffers. Instead, this method is better suited to a pull-style buffer source such as an AVAssetReaderOutput object.When using a push-style buffer source, it is generally better to immediately append each buffer to the asset writer input, directly as it is received using appendSampleBuffer:. Using this strategy, it is often possible to avoid having to queue up buffers in between the buffer source and the asset writer input. Note that many of these push-style buffer sources also produce buffers in real-time, in which case you should set expectsMediaDataInRealTime to YES.

Parameters:

  • queue

    The queue on which block should be invoked.

  • block

    The block the input should invoke to obtain media data.

Returns: