AssetSessionExporter
open class AssetSessionExporter : NSObject, @unchecked Sendable
🔄 AssetSessionExporter, export and transcode media in Swift
-
export(asset:
outputFileType: outputURL: metadata: videoInputConfiguration: videoOutputConfiguration: audioOutputConfiguration: progressHandler: completionHandler: ) Initiates a AssetSessionExport on the asset
Declaration
Swift
public static func export( asset: AVAsset, outputFileType: AVFileType? = AVFileType.mp4, outputURL: URL, metadata: [AVMetadataItem]? = nil, videoInputConfiguration: [String: Any]? = nil, videoOutputConfiguration: [String: Any], audioOutputConfiguration: [String: Any], progressHandler: AssetSessionExporter.ProgressHandler? = nil, completionHandler: AssetSessionExporter.CompletionHandler? = nil )
Parameters
asset
The asset to export
outputFileType
type of resulting file to create
outputURL
location of resulting file
metadata
data to embed in the result
videoInputConfiguration
video input configuration
videoOutputConfiguration
video output configuration
audioOutputConfiguration
audio output configuration
progressHandler
progress fraction handler
completionHandler
completion handler
-
The natural dimensions of the asset.
Declaration
Swift
public static func naturalSize(for asset: AVAsset) -> CGSize
-
Input asset for export, provided when initialized.
Declaration
Swift
public var asset: AVAsset?
-
Enables video composition and parameters for the session.
Declaration
Swift
public var videoComposition: AVVideoComposition?
-
Enables audio mixing and parameters for the session.
Declaration
Swift
public var audioMix: AVAudioMix?
-
Output file location for the session.
Declaration
Swift
public var outputURL: URL?
-
Output file type. UTI string defined in
AVMediaFormat.h
.Declaration
Swift
public var outputFileType: AVFileType?
-
Time range or limit of an export from
kCMTimeZero
tokCMTimePositiveInfinity
Declaration
Swift
public var timeRange: CMTimeRange
-
Indicates if an export session should expect media data in real time.
Declaration
Swift
public var expectsMediaDataInRealTime: Bool
-
Indicates if an export should be optimized for network use.
Declaration
Swift
public var optimizeForNetworkUse: Bool
-
Metadata to be added to an export.
Declaration
Swift
public var metadata: [AVMetadataItem]?
-
Video input configuration dictionary, using keys defined in
<CoreVideo/CVPixelBuffer.h>
Declaration
Swift
public var videoInputConfiguration: [String : Any]?
-
Video output configuration dictionary, using keys defined in
<AVFoundation/AVVideoSettings.h>
Declaration
Swift
public var videoOutputConfiguration: [String : Any]?
-
Audio output configuration dictionary, using keys defined in
<AVFoundation/AVAudioSettings.h>
Declaration
Swift
public var audioOutputConfiguration: [String : Any]?
-
Export session status state.
Declaration
Swift
public var status: AVAssetExportSession.Status { get }
-
Session exporting progress from 0 to 1.
Declaration
Swift
public var progress: Float { get }
-
Initializes a session with an asset to export.
Declaration
Swift
public convenience init(withAsset asset: AVAsset)
Parameters
asset
The asset to export.
-
Undocumented
Declaration
Swift
override public init()
-
Undocumented
Declaration
Swift
open func validateVideoOutputConfiguration() -> Bool
-
Completion handler type for when an export finishes.
Declaration
Swift
public typealias CompletionHandler = @MainActor @Sendable (Swift.Result<AVAssetExportSession.Status, Error>) -> Void
-
Progress handler type
Declaration
Swift
public typealias ProgressHandler = @Sendable (_ progress: Float) -> Void
-
Render handler type for frame processing
Declaration
Swift
public typealias RenderHandler = @Sendable (_ renderFrame: CVPixelBuffer, _ presentationTime: CMTime, _ resultingBuffer: CVPixelBuffer) -> Void
-
Initiates an export session.
Throws
Failure indication thrown when an error has occurred during export.Declaration
Swift
public func export(renderHandler: RenderHandler? = nil, progressHandler: ProgressHandler? = nil, completionHandler: CompletionHandler? = nil)
Parameters
completionHandler
Handler called when an export session completes.
-
Cancels any export in progress.
Declaration
Swift
public func cancelExport()