Class: AVAssetWriter
Overview
You use an AVAssetWriter object to write media data to a new file of a specified audiovisual container type, such as a QuickTime movie file or an MPEG-4 file, with support for automatic interleaving of media data for multiple concurrent tracks.
Instance Attribute Summary (collapse)
-
- availableMediaTypes
readonly
The media types for which inputs can be added (read-only) Some media types may not be accepted within the type of file with which the writer was initialized.
-
- error
readonly
If the receiver's status is AVAssetWriterStatusFailed, describes the error that caused the failure.
-
- inputs
readonly
The asset writer inputs associated with the asset writer.
-
- metadata
The collection of metadata for association with the asset and for carriage in the output file.
-
- movieFragmentInterval
The time to elapse between writing movie fragments.
-
- movieTimeScale
Specifies the asset-level time scale to be used.
-
- outputFileType
readonly
The file format of the writer’s output.
-
- outputURL
readonly
The URL to which output is directed.
-
- shouldOptimizeForNetworkUse
Indicates whether the output file should be written in way that makes it more suitable for playback over a network.
-
- status
readonly
The status of writing samples to the receiver's output file.
Class Method Summary (collapse)
-
+ assetWriterWithURL:fileType:error:
Returns an asset writer for writing to the file identified by a given URL in a format specified by a given UTI.
Instance Method Summary (collapse)
-
- addInput:
Adds an input to the receiver.
-
- canAddInput:
Returns a Boolean value that indicates whether a given input can be added to the receiver.
-
- canApplyOutputSettings:forMediaType:
Returns a Boolean value that indicates whether give output settings are supported for a specified media type.
-
- cancelWriting
Instructs the writer to cancel writing.
-
- endSessionAtSourceTime:
Concludes an explicit sample-writing session.
-
- finishWritingWithCompletionHandler:
Marks all unfinished inputs as finished and completes the writing of the output file.
-
- initWithURL:fileType:error:
Initializes an asset writer for writing to the file identified by a given URL in a format specified by a given UTI.
-
- startSessionAtSourceTime:
Initiates a sample-writing session for the output asset.
-
- startWriting
Tells the writer to start writing its output.
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
- (Array) availableMediaTypes (readonly)
The media types for which inputs can be added (read-only) Some media types may not be accepted within the type of file with which the writer was initialized.
- (NSError) error (readonly)
If the receiver's status is AVAssetWriterStatusFailed, describes the error that caused the failure. (read-only) The value of this property is an error object that describes what caused the receiver to no longer be able to write to its output file. If the receiver's status is not AVAssetWriterStatusFailed, the value of this property is nil.
- (Array) inputs (readonly)
The asset writer inputs associated with the asset writer. (read-only) The array contains AVAssetWriterInput objects.
- (Array) metadata
The collection of metadata for association with the asset and for carriage in the output file. The array contains AVMetadataItem objects.
- (CMTime) movieFragmentInterval
The time to elapse between writing movie fragments. This property only applies to the QuickTime movie file type. Sometimes a write operation may be unexpectedly interrupted (because a process crashes, for example). By using movie fragments, such a partially-written QuickTime movie file can be successfully opened and played up to the largest multiple of movieFragmentInterval smaller than the point at which the write operation was interrupted.The default value is kCMTimeInvalid, which means that movie fragments should not be used, that only a movie atom describing all of the media in the file should be written.
- (CMTimeScale) movieTimeScale
Specifies the asset-level time scale to be used. For file types that contain a moov atom, such as QuickTime Movie files, specifies the asset-level time scale to be used.The default value is 0, which indicates that you should choose a convenient value, if applicable.
- (String) outputFileType (readonly)
The file format of the writer’s output. (read-only) The format is identified by the UTI, specified when the writer is initialized.
- (NSURL) outputURL (readonly)
The URL to which output is directed. (read-only) The URL is the same as that specified when the writer is initialized.
- (Boolean) shouldOptimizeForNetworkUse
Indicates whether the output file should be written in way that makes it more suitable for playback over a network. When the value of this property is YES, the output file will be written in such a way that playback can start after only a small amount of the file is downloaded.The default value is NO.
- (AVAssetWriterStatus) status (readonly)
The status of writing samples to the receiver's output file. (read-only) The value of this property is an AVAssetWriterStatus constant that indicates whether writing is in progress, has completed successfully, has been canceled, or has failed. If an attempt to append samples fails, you can check the value of this property to determine why no more samples could be written.
Class Method Details
+ (AVAssetWriter) assetWriterWithURL(outputURL, fileType:outputFileType, error:outError)
Returns an asset writer for writing to the file identified by a given URL in a format specified by a given UTI. Writing will fail if a file already exists at URL. UTIs for container formats that can be written are declared in AVMediaFormat.h.
Instance Method Details
- (Object) addInput(input)
Adds an input to the receiver. Inputs are created with a media type and output settings. These both must be compatible with the receiver.
- (Boolean) canAddInput(input)
Returns a Boolean value that indicates whether a given input can be added to the receiver. You cannot add an input that accepts media data of a type that is not compatible with the receiver, or with output settings that are not compatible with the receiver.
- (Boolean) canApplyOutputSettings(outputSettings, forMediaType:mediaType)
Returns a Boolean value that indicates whether give output settings are supported for a specified media type. You can use this method to test, for example, whether video output settings that specify H.264 compression will fail (as would be the case if the container format for which the writer was initialized does not support the carriage of H.264-compressed video).
- (Object) cancelWriting
Instructs the writer to cancel writing. This method blocks until writing is canceled.
- (Object) endSessionAtSourceTime(endTime)
Concludes an explicit sample-writing session. You may invoke this method to complete a session you began by invoking startSessionAtSourceTime:.You do not need to call this method; if you call finishWriting without calling this method, the session’s effective end time will be the latest end timestamp of the session’s samples (that is, no samples will be edited out at the end).The endTime defines the moment on the timeline of source samples at which the session ends. In the case of the QuickTime movie file format, each sample-writing session’s startTime…endTime pair corresponds to a period of movie time into which the session’s samples are inserted. Samples with later timestamps will be still be added to the media but will be edited out of the movie. So if the first session has duration D1 = endTime - startTime, it will be inserted into the movie at movie time 0 through D1; the second session would be inserted into the movie at movie time D1 through D1+D2, and so on.It is legal to have a session with no samples; this will cause creation of an empty edit of the prescribed duration.
- (Object) finishWritingWithCompletionHandler(handler)
Marks all unfinished inputs as finished and completes the writing of the output file. This method returns immediately and causes its work to be performed asynchronously. To determine whether the operation succeeded, you can check the value of the status property within the handler parameter. If the status is AVAssetWriterStatusFailed, then the error property will contain an instance of NSError that describes the failure.To guarantee that all sample buffers are successfully written, you must ensure that all calls to appendSampleBuffer: and appendPixelBuffer:withPresentationTime: have returned before invoking this method.
- (Object) initWithURL(outputURL, fileType:outputFileType, error:outError)
Initializes an asset writer for writing to the file identified by a given URL in a format specified by a given UTI. Writing will fail if a file already exists at URL. UTIs for container formats that can be written are declared in AVMediaFormat.h.
- (Object) startSessionAtSourceTime(startTime)
Initiates a sample-writing session for the output asset. Sequences of sample data appended to the asset writer inputs are considered to fall within “sample-writing sessions.” You must call this method to begin one of these sessions.Each writing session has a start time which, where allowed by the file format being written, defines the mapping from the timeline of source samples onto the file’s timeline. In the case of the QuickTime movie file format, the first session begins at movie time 0, so a sample appended with timestamp T will be played at movie time (T-startTime). Samples with timestamps before startTime will still be added to the output media but will be edited out of the movie. If the earliest buffer for an input is later than startTime, an empty edit will be inserted to preserve synchronization between tracks of the output asset.
- (Boolean) startWriting
Tells the writer to start writing its output. You must call this method after all inputs have added and other configuration properties have been set to tell the receiver to prepare for writing. After invoking this method, you can start writing sessions using startSessionAtSourceTime: and can write media samples using the methods provided by each of the writer’s inputs.status signals the terminal state of the asset reader, and if a failure occurs, error describes the failure.