Class AVAssetExportSession

  • All Implemented Interfaces:
    NSObject

    public class AVAssetExportSession
    extends NSObject
    AVAssetExportSession An AVAssetExportSession creates a new timed media resource from the contents of an existing AVAsset in the form described by a specified export preset. Prior to initializing an instance of AVAssetExportSession, you can invoke +allExportPresets to obtain the complete list of presets available. Use +exportPresetsCompatibleWithAsset: to obtain a list of presets that are compatible with a specific AVAsset. To configure an export, initialize an AVAssetExportSession with an AVAsset that contains the source media, an AVAssetExportPreset, the output file type, (a UTI string from those defined in AVMediaFormat.h) and the output URL. After configuration is complete, invoke exportAsynchronouslyWithCompletionHandler: to start the export process. This method returns immediately; the export is performed asynchronously. Invoke the -progress method to check on the progress. Note that in some cases, depending on the capabilities of the device, when multiple exports are attempted at the same time some may be queued until others have been completed. When this happens, the status of a queued export will indicate that it's "waiting". Whether the export fails, completes, or is cancelled, the completion handler you supply to -exportAsynchronouslyWithCompletionHandler: will be called. Upon completion, the status property indicates whether the export has completed successfully. If it has failed, the value of the error property supplies additional information about the reason for the failure.
    • Constructor Detail

      • AVAssetExportSession

        protected AVAssetExportSession​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allExportPresets

        public static NSArray<java.lang.String> allExportPresets()
        allExportPresets Returns all available export preset names. Returns an array of NSStrings with the names of all available presets. Note that not all presets are compatible with all AVAssets.
        Returns:
        An NSArray containing an NSString for each of the available preset names.
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • determineCompatibilityOfExportPresetWithAssetOutputFileTypeCompletionHandler

        public static void determineCompatibilityOfExportPresetWithAssetOutputFileTypeCompletionHandler​(java.lang.String presetName,
                                                                                                        AVAsset asset,
                                                                                                        java.lang.String outputFileType,
                                                                                                        AVAssetExportSession.Block_determineCompatibilityOfExportPresetWithAssetOutputFileTypeCompletionHandler handler)
        determineCompatibilityOfExportPreset:withAsset:outputFileType:completionHandler: Performs an inspection on the compatibility of an export preset, AVAsset and output file type. Calls the completion handler with YES if the arguments are compatible; NO otherwise. Not all export presets are compatible with all AVAssets and file types. This method can be used to query compatibility. In order to ensure that the setup and running of an export operation will succeed using a given preset no significant changes (such as adding or deleting tracks) should be made to the asset between retrieving compatible identifiers and performing the export operation.
        Parameters:
        presetName - An NSString specifying the name of the preset template for the export.
        asset - An AVAsset object that is intended to be exported.
        outputFileType - An AVFileType indicating a file type to check; or nil, to query whether there are any compatible types.
        handler - A block called with the compatibility result.
      • exportPresetsCompatibleWithAsset

        public static NSArray<java.lang.String> exportPresetsCompatibleWithAsset​(AVAsset asset)
        exportPresetsCompatibleWithAsset: Returns only the identifiers compatible with the given AVAsset object. Not all export presets are compatible with all AVAssets. For example an video only asset is not compatible with an audio only preset. This method returns only the identifiers for presets that will be compatible with the given asset. A client should pass in an AVAsset that is ready to be exported. In order to ensure that the setup and running of an export operation will succeed using a given preset no significant changes (such as adding or deleting tracks) should be made to the asset between retrieving compatible identifiers and performing the export operation. This method will access the tracks property of the AVAsset to build the returned NSArray. To avoid blocking the calling thread, the tracks property should be loaded using the AVAsynchronousKeyValueLoading protocol before calling this method.
        Parameters:
        asset - An AVAsset object that is intended to be exported.
        Returns:
        An NSArray containing NSString values for the identifiers of compatible export types. The array is a complete list of the valid identifiers that can be used as arguments to initWithAsset:presetName: with the specified asset.
      • exportSessionWithAssetPresetName

        public static AVAssetExportSession exportSessionWithAssetPresetName​(AVAsset asset,
                                                                            java.lang.String presetName)
        exportSessionWithAsset:presetName: Returns an instance of AVAssetExportSession for the specified source asset and preset. If the specified asset belongs to a mutable subclass of AVAsset, AVMutableComposition or AVMutableMovie, the results of any export-related operation are undefined if you mutate the asset after the operation commences. These operations include but are not limited to: 1) testing the compatibility of export presets with the asset, 2) calculating the maximum duration or estimated length of the output file, and 3) the export operation itself.
        Parameters:
        asset - An AVAsset object that is intended to be exported.
        presetName - An NSString specifying the name of the preset template for the export.
        Returns:
        An instance of AVAssetExportSession.
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • asset

        public AVAsset asset()
        Indicates the instance of AVAsset with which the AVExportSession was initialized
      • audioMix

        public AVAudioMix audioMix()
        Indicates whether non-default audio mixing is enabled for export and supplies the parameters for audio mixing. Ignored when export preset is AVAssetExportPresetPassthrough.
      • audioTimePitchAlgorithm

        public java.lang.String audioTimePitchAlgorithm()
        Indicates the processing algorithm used to manage audio pitch for scaled audio edits. Constants for various time pitch algorithms, e.g. AVAudioTimePitchAlgorithmSpectral, are defined in AVAudioProcessingSettings.h. An NSInvalidArgumentException will be raised if this property is set to a value other than the constants defined in that file. The default value is AVAudioTimePitchAlgorithmSpectral.
      • canPerformMultiplePassesOverSourceMediaData

        public boolean canPerformMultiplePassesOverSourceMediaData()
        [@property] canPerformMultiplePassesOverSourceMediaData Determines whether the export session can perform multiple passes over the source media to achieve better results. When the value for this property is YES, the export session can produce higher quality results at the expense of longer export times. Setting this property to YES may also require the export session to write temporary data to disk during the export. To control the location of temporary data, use the property directoryForTemporaryFiles. The default value is NO. Not all export session configurations can benefit from performing multiple passes over the source media. In these cases, setting this property to YES has no effect. This property cannot be set after the export has started.
      • cancelExport

        public void cancelExport()
        cancelExport Cancels the execution of an export session. Cancel can be invoked when the export is running.
      • customVideoCompositor

        public AVVideoCompositing customVideoCompositor()
        Indicates the custom video compositor instance used, if any
      • determineCompatibleFileTypesWithCompletionHandler

        public void determineCompatibleFileTypesWithCompletionHandler​(AVAssetExportSession.Block_determineCompatibleFileTypesWithCompletionHandler handler)
        determineCompatibleFileTypesWithCompletionHandler: Performs an inspection on the AVAsset and Preset the object was initialized with to determine a list of file types the ExportSession can write. This method is different than the supportedFileTypes property in that it performs an inspection of the AVAsset in order to determine its compatibility with each of the session's supported file types.
        Parameters:
        handler - Called when the inspection completes with an array of file types the ExportSession can write. Note that this may have a count of zero.
      • directoryForTemporaryFiles

        public NSURL directoryForTemporaryFiles()
        [@property] directoryForTemporaryFiles Specifies a directory that is suitable for containing temporary files generated during the export process AVAssetExportSession may need to write temporary files when configured in certain ways, such as when canPerformMultiplePassesOverSourceMediaData is set to YES. This property can be used to control where in the filesystem those temporary files are created. All temporary files will be deleted when the export is completed, is canceled, or fails. When the value of this property is nil, the export session will choose a suitable location when writing temporary files. The default value is nil. This property cannot be set after the export has started. The export will fail if the URL points to a location that is not a directory, does not exist, is not on the local file system, or if a file cannot be created in this directory (for example, due to insufficient permissions or sandboxing restrictions).
      • error

        public NSError error()
        describes the error that occured if the export status is AVAssetExportSessionStatusFailed
      • estimatedOutputFileLength

        public long estimatedOutputFileLength()
        Indicates the estimated byte size of exported file. Returns zero when export preset is AVAssetExportPresetPassthrough, AVAssetExportPresetAppleProRes422LPCM or AVAssetExportPresetAppleProRes4444LPCM. This property will also return zero if a numeric value (ie. not invalid, indefinite, or infinite) for the timeRange property has not been set. Note that the returned value does not take into account the source asset information. For a more accurate estimation, use estimateOutputFileLengthWithCompletionHandler.
      • exportAsynchronouslyWithCompletionHandler

        public void exportAsynchronouslyWithCompletionHandler​(AVAssetExportSession.Block_exportAsynchronouslyWithCompletionHandler handler)
        exportAsynchronouslyWithCompletionHandler: Starts the asynchronous execution of an export session. Initiates an asynchronous export operation and returns immediately.
        Parameters:
        handler - If internal preparation for export fails, the handler will be invoked synchronously. The handler may also be called asynchronously after -exportAsynchronouslyWithCompletionHandler: returns, in the following cases: 1) if a failure occurs during the export, including failures of loading, re-encoding, or writing media data to the output, 2) if -cancelExport is invoked, 3) if export session succeeds, having completely written its output to the outputURL. In each case, AVAssetExportSession.status will signal the terminal state of the asset reader, and if a failure occurs, the NSError that describes the failure can be obtained from the error property.
      • fileLengthLimit

        public long fileLengthLimit()
        Indicates the file length that the output of the session should not exceed. Depending on the content of the source asset, it is possible for the output to slightly exceed the file length limit. The length of the output file should be tested if you require that a strict limit be observed before making use of the output. See also maxDuration and timeRange.
      • initWithAssetPresetName

        public AVAssetExportSession initWithAssetPresetName​(AVAsset asset,
                                                            java.lang.String presetName)
        initWithAsset:presetName: Initialize an AVAssetExportSession with the specified preset and set the source to the contents of the asset. If the specified asset belongs to a mutable subclass of AVAsset, AVMutableComposition or AVMutableMovie, the results of any export-related operation are undefined if you mutate the asset after the operation commences. These operations include but are not limited to: 1) testing the compatibility of export presets with the asset, 2) calculating the maximum duration or estimated length of the output file, and 3) the export operation itself.
        Parameters:
        asset - An AVAsset object that is intended to be exported.
        presetName - An NSString specifying the name of the preset template for the export.
        Returns:
        Returns the initialized AVAssetExportSession.
      • maxDuration

        public CMTime maxDuration()
        Provides an estimate of the maximum duration of exported media that is possible given the source asset, the export preset, and the current value of fileLengthLimit. The export will not stop when it reaches this maximum duration; set the timeRange property to export only a certain time range.
      • metadata

        public NSArray<? extends AVMetadataItem> metadata()
        Specifies an NSArray of AVMetadataItems that are to be written to the output file by the export session. If the value of this key is nil, any existing metadata in the exported asset will be translated as accurately as possible into the appropriate metadata keyspace for the output file and written to the output.
      • metadataItemFilter

        public AVMetadataItemFilter metadataItemFilter()
        Specifies a filter object to be used during export to determine which metadata items should be transferred from the source asset. If the value of this key is nil, no filter will be applied. This is the default. The filter will not be applied to metadata set with via the metadata property. To apply the filter to metadata before it is set on the metadata property, see the methods in AVMetadataItem's AVMetadataItemArrayFiltering category.
      • outputFileType

        public java.lang.String outputFileType()
        Indicates the type of file to be written by the session. The value of this property must be set before you invoke -exportAsynchronouslyWithCompletionHandler:; otherwise -exportAsynchronouslyWithCompletionHandler: will raise an NSInternalInconsistencyException. Setting the value of this property to a file type that's not among the session's supported file types will result in an NSInvalidArgumentException. See supportedFileTypes.
      • outputURL

        public NSURL outputURL()
        Indicates the URL of the export session's output. You may use UTTypeCopyPreferredTagWithClass(outputFileType, kUTTagClassFilenameExtension) to obtain an appropriate path extension for the outputFileType you have specified. For more information about UTTypeCopyPreferredTagWithClass and kUTTagClassFilenameExtension, on iOS see and on Mac OS X see .
      • presetName

        public java.lang.String presetName()
        Indicates the name of the preset with which the AVExportSession was initialized
      • progress

        public float progress()
        Specifies the progress of the export on a scale from 0 to 1.0. A value of 0 means the export has not yet begun, A value of 1.0 means the export is complete. This property is not key-value observable.
      • setAudioMix

        public void setAudioMix​(AVAudioMix value)
        Indicates whether non-default audio mixing is enabled for export and supplies the parameters for audio mixing. Ignored when export preset is AVAssetExportPresetPassthrough.
      • setAudioTimePitchAlgorithm

        public void setAudioTimePitchAlgorithm​(java.lang.String value)
        Indicates the processing algorithm used to manage audio pitch for scaled audio edits. Constants for various time pitch algorithms, e.g. AVAudioTimePitchAlgorithmSpectral, are defined in AVAudioProcessingSettings.h. An NSInvalidArgumentException will be raised if this property is set to a value other than the constants defined in that file. The default value is AVAudioTimePitchAlgorithmSpectral.
      • setCanPerformMultiplePassesOverSourceMediaData

        public void setCanPerformMultiplePassesOverSourceMediaData​(boolean value)
        [@property] canPerformMultiplePassesOverSourceMediaData Determines whether the export session can perform multiple passes over the source media to achieve better results. When the value for this property is YES, the export session can produce higher quality results at the expense of longer export times. Setting this property to YES may also require the export session to write temporary data to disk during the export. To control the location of temporary data, use the property directoryForTemporaryFiles. The default value is NO. Not all export session configurations can benefit from performing multiple passes over the source media. In these cases, setting this property to YES has no effect. This property cannot be set after the export has started.
      • setDirectoryForTemporaryFiles

        public void setDirectoryForTemporaryFiles​(NSURL value)
        [@property] directoryForTemporaryFiles Specifies a directory that is suitable for containing temporary files generated during the export process AVAssetExportSession may need to write temporary files when configured in certain ways, such as when canPerformMultiplePassesOverSourceMediaData is set to YES. This property can be used to control where in the filesystem those temporary files are created. All temporary files will be deleted when the export is completed, is canceled, or fails. When the value of this property is nil, the export session will choose a suitable location when writing temporary files. The default value is nil. This property cannot be set after the export has started. The export will fail if the URL points to a location that is not a directory, does not exist, is not on the local file system, or if a file cannot be created in this directory (for example, due to insufficient permissions or sandboxing restrictions).
      • setFileLengthLimit

        public void setFileLengthLimit​(long value)
        Indicates the file length that the output of the session should not exceed. Depending on the content of the source asset, it is possible for the output to slightly exceed the file length limit. The length of the output file should be tested if you require that a strict limit be observed before making use of the output. See also maxDuration and timeRange.
      • setMetadata

        public void setMetadata​(NSArray<? extends AVMetadataItem> value)
        Specifies an NSArray of AVMetadataItems that are to be written to the output file by the export session. If the value of this key is nil, any existing metadata in the exported asset will be translated as accurately as possible into the appropriate metadata keyspace for the output file and written to the output.
      • setMetadataItemFilter

        public void setMetadataItemFilter​(AVMetadataItemFilter value)
        Specifies a filter object to be used during export to determine which metadata items should be transferred from the source asset. If the value of this key is nil, no filter will be applied. This is the default. The filter will not be applied to metadata set with via the metadata property. To apply the filter to metadata before it is set on the metadata property, see the methods in AVMetadataItem's AVMetadataItemArrayFiltering category.
      • setOutputFileType

        public void setOutputFileType​(java.lang.String value)
        Indicates the type of file to be written by the session. The value of this property must be set before you invoke -exportAsynchronouslyWithCompletionHandler:; otherwise -exportAsynchronouslyWithCompletionHandler: will raise an NSInternalInconsistencyException. Setting the value of this property to a file type that's not among the session's supported file types will result in an NSInvalidArgumentException. See supportedFileTypes.
      • setOutputURL

        public void setOutputURL​(NSURL value)
        Indicates the URL of the export session's output. You may use UTTypeCopyPreferredTagWithClass(outputFileType, kUTTagClassFilenameExtension) to obtain an appropriate path extension for the outputFileType you have specified. For more information about UTTypeCopyPreferredTagWithClass and kUTTagClassFilenameExtension, on iOS see and on Mac OS X see .
      • setShouldOptimizeForNetworkUse

        public void setShouldOptimizeForNetworkUse​(boolean value)
        indicates that the output file should be optimized for network use, e.g. that a QuickTime movie file should support "fast start"
      • setTimeRange

        public void setTimeRange​(CMTimeRange value)
        Specifies a time range to be exported from the source. The default timeRange of an export session is kCMTimeZero..kCMTimePositiveInfinity, meaning that the full duration of the asset will be exported.
      • setVideoComposition

        public void setVideoComposition​(AVVideoComposition value)
        Indicates whether video composition is enabled for export and supplies the instructions for video composition. Ignored when export preset is AVAssetExportPresetPassthrough.
      • shouldOptimizeForNetworkUse

        public boolean shouldOptimizeForNetworkUse()
        indicates that the output file should be optimized for network use, e.g. that a QuickTime movie file should support "fast start"
      • status

        public long status()
        indicates the status of the export session
      • supportedFileTypes

        public NSArray<java.lang.String> supportedFileTypes()
        Indicates the types of files the target can write, according to the preset the target was initialized with. Does not perform an inspection of the AVAsset to determine whether its contents are compatible with the supported file types. If you need to make that determination before initiating the export, use - (void)determineCompatibleFileTypesWithCompletionHandler:(void (^)(NSArray *compatibleFileTypes))handler:.
      • timeRange

        public CMTimeRange timeRange()
        Specifies a time range to be exported from the source. The default timeRange of an export session is kCMTimeZero..kCMTimePositiveInfinity, meaning that the full duration of the asset will be exported.
      • videoComposition

        public AVVideoComposition videoComposition()
        Indicates whether video composition is enabled for export and supplies the instructions for video composition. Ignored when export preset is AVAssetExportPresetPassthrough.
      • estimateMaximumDurationWithCompletionHandler

        public void estimateMaximumDurationWithCompletionHandler​(AVAssetExportSession.Block_estimateMaximumDurationWithCompletionHandler handler)
        estimateMaximumDurationWithCompletionHandler: Starts the asynchronous execution of estimating the maximum duration of the export based on the asset, preset, and fileLengthLimit associated with the export session. If fileLengthLimit is not set on the export session, fileLengthLimit will be assumed to be the maximum file size specified by the preset (if any); else infinite.
        Parameters:
        handler - A block called with the estimated maximum duration, or kCMTimeInvalid if an error occurs. The error parameter will be non-nil if an error occurs.
      • estimateOutputFileLengthWithCompletionHandler

        public void estimateOutputFileLengthWithCompletionHandler​(AVAssetExportSession.Block_estimateOutputFileLengthWithCompletionHandler handler)
        estimateOutputFileLengthWithCompletionHandler: Starts the asynchronous execution of estimating the output file length of the export based on the asset, preset, and timeRange associated with the export session. If timeRange is not set on the export session, timeRange will be assumed to be the full time range of the asset.
        Parameters:
        handler - A block called with the estimated output file length in bytes, if it can be accurately determined; 0 otherwise. The error parameter will be non-nil if an error occurs.