### Install NextLevelSessionExporter Source: https://nextlevel.github.io/NextLevelSessionExporter/index.html Instructions for installing the NextLevelSessionExporter library using various package managers. ```bash # CocoaPods pod "NextLevelSessionExporter", "~> 0.4.0" ``` ```bash # Carthage github "nextlevel/NextLevelSessionExporter" ~> 0.4.0 ``` ```swift # Swift PM let package = Package( dependencies: [ .Package(url: "https://github.com/nextlevel/NextLevelSessionExporter", majorVersion: 0) ] ) ``` -------------------------------- ### Initiate NextLevel Session Export Source: https://nextlevel.github.io/NextLevelSessionExporter/Extensions/AVAsset.html Use this method to start exporting an AVAsset. Configure video and audio output settings, and provide handlers for progress and completion. ```swift public func nextlevel_export(outputFileType: AVFileType? = AVFileType.mp4, outputURL: URL, metadata: [AVMetadataItem]? = nil, videoInputConfiguration: [String : Any]? = nil, videoOutputConfiguration: [String : Any], audioOutputConfiguration: [String : Any], progressHandler: NextLevelSessionExporter.ProgressHandler? = nil, completionHandler: NextLevelSessionExporter.CompletionHandler? = nil) ``` -------------------------------- ### Export Media with AVAsset Extension Source: https://nextlevel.github.io/NextLevelSessionExporter/index.html Example demonstrating how to export media using the AVAsset extension provided by NextLevelSessionExporter. This method simplifies the export process by directly operating on an AVAsset. ```swift let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) .appendingPathComponent(ProcessInfo().globallyUniqueString) .appendingPathExtension("mp4") exporter.outputURL = tmpURL let compressionDict: [String: Any] = [ AVVideoAverageBitRateKey: NSNumber(integerLiteral: 6000000), AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel as String, ] let videoOutputConfig = [ AVVideoCodecKey: AVVideoCodec.h264, AVVideoWidthKey: NSNumber(integerLiteral: 1920), AVVideoHeightKey: NSNumber(integerLiteral: 1080), AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill, AVVideoCompressionPropertiesKey: compressionDict ] let audioOutputConfig = [ AVFormatIDKey: kAudioFormatMPEG4AAC, AVEncoderBitRateKey: NSNumber(integerLiteral: 128000), AVNumberOfChannelsKey: NSNumber(integerLiteral: 2), AVSampleRateKey: NSNumber(value: Float(44100)) ] let asset = AVAsset(url: Bundle.main.url(forResource: "TestVideo", withExtension: "mov")!) asset.nextlevel_export(outputURL: tmpURL, videoOutputConfiguration: videoOutputConfig, audioOutputConfiguration: audioOutputConfig) ``` -------------------------------- ### Export Media with NextLevelSessionExporter Instance Source: https://nextlevel.github.io/NextLevelSessionExporter/index.html Example showing how to use an instance of NextLevelSessionExporter for media export. This provides more control over the export process, including progress and completion handlers. ```swift let exporter = NextLevelSessionExporter(withAsset: asset) exporter.outputFileType = AVFileType.mp4 let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) .appendingPathComponent(ProcessInfo().globallyUniqueString) .appendingPathExtension("mp4") exporter.outputURL = tmpURL let compressionDict: [String: Any] = [ AVVideoAverageBitRateKey: NSNumber(integerLiteral: 6000000), AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel as String, ] exporter.videoOutputConfiguration = [ AVVideoCodecKey: AVVideoCodec.h264, AVVideoWidthKey: NSNumber(integerLiteral: 1920), AVVideoHeightKey: NSNumber(integerLiteral: 1080), AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill, AVVideoCompressionPropertiesKey: compressionDict ] exporter.audioOutputConfiguration = [ AVFormatIDKey: kAudioFormatMPEG4AAC, AVEncoderBitRateKey: NSNumber(integerLiteral: 128000), AVNumberOfChannelsKey: NSNumber(integerLiteral: 2), AVSampleRateKey: NSNumber(value: Float(44100)) ] exporter.export(progressHandler: { (progress) in print(progress) }, completionHandler: { result in switch result { case .success(let status): switch status { case .completed: print("NextLevelSessionExporter, export completed, \(exporter.outputURL?.description ?? "")") break default: print("NextLevelSessionExporter, did not complete") break } break case .failure(let error): print("NextLevelSessionExporter, failed to export \(error)") break } }) ``` -------------------------------- ### NextLevelSessionExporterError Setup Failure Case Source: https://nextlevel.github.io/NextLevelSessionExporter/Enums/NextLevelSessionExporterError.html Represents an error that occurs during the initial setup phase of the session exporter. ```swift case setupFailure ``` -------------------------------- ### Initializer with Asset Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Initializes a new export session with a specified AVAsset. ```swift public convenience init(withAsset asset: AVAsset) ``` -------------------------------- ### Export Method Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Initiates the media export process. It can optionally accept handlers for rendering frames, reporting progress, and completion. ```swift public func export(renderHandler: RenderHandler? = nil, progressHandler: ProgressHandler? = nil, completionHandler: CompletionHandler? = nil) ``` -------------------------------- ### VideoInputConfiguration Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html A dictionary for configuring video input, using keys defined in CoreVideo. ```swift public var videoInputConfiguration: [String : Any]? ``` -------------------------------- ### AudioOutputConfiguration Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html A dictionary for configuring audio output settings, using keys defined in AVFoundation. ```swift public var audioOutputConfiguration: [String : Any]? ``` -------------------------------- ### VideoOutputConfiguration Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html A dictionary for configuring video output settings, using keys defined in AVFoundation. ```swift public var videoOutputConfiguration: [String : Any]? ``` -------------------------------- ### Asset Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html The input AVAsset for the export session. This should be provided during initialization. ```swift public var asset: AVAsset? ``` -------------------------------- ### OutputURL Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Specifies the file location for the exported media. ```swift public var outputURL: URL? ``` -------------------------------- ### NextLevelSessionExporter Initializers Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Details the initializers for creating a NextLevelSessionExporter instance, including initializing with an asset or a default initializer. ```APIDOC ## NextLevelSessionExporter Initializers ### init(withAsset:) Initializes a session with an asset to export. #### Parameters - **asset** (`AVAsset`) - The asset to export. ### init() Undocumented initializer. - **Declaration**: `public override init()` ``` -------------------------------- ### VideoComposition Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Allows for video composition and setting parameters for the export session. ```swift public var videoComposition: AVVideoComposition? ``` -------------------------------- ### nextlevel_export Source: https://nextlevel.github.io/NextLevelSessionExporter/Extensions/AVAsset.html Initiates a NextLevelSessionExport on the asset. This method allows for custom configuration of video and audio output, metadata, and progress/completion handling. ```APIDOC ## nextlevel_export ### Description Initiates a NextLevelSessionExport on the asset. This method allows for custom configuration of video and audio output, metadata, and progress/completion handling. ### Method public func ### Endpoint AVAsset ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **outputFileType** (AVFileType? = AVFileType.mp4) - type of resulting file to create - **outputURL** (URL) - location of resulting file - **metadata** ([AVMetadataItem]? = nil) - data to embed in the result - **videoInputConfiguration** ([String : Any]? = nil) - video input configuration - **videoOutputConfiguration** ([String : Any]) - video output configuration - **audioOutputConfiguration** ([String : Any]) - audio output configuration - **progressHandler** (NextLevelSessionExporter.ProgressHandler? = nil) - progress fraction handler - **completionHandler** (NextLevelSessionExporter.CompletionHandler? = nil) - completion handler ### Request Example ```swift // Example usage (assuming necessary setup for AVAsset and configurations) let asset: AVAsset = ... // Your AVAsset instance let outputURL: URL = ... // Your output URL let videoConfig: [String: Any] = ... // Your video output configuration let audioConfig: [String: Any] = ... // Your audio output configuration asset.nextlevel_export(outputURL: outputURL, videoOutputConfiguration: videoConfig, audioOutputConfiguration: audioConfig) { progress in // Handle progress updates print("Export progress: \(progress * 100)%") } completionHandler: { result, error in if let error = error { print("Export failed: \(error.localizedDescription)") } else { print("Export completed successfully.") } } ``` ### Response #### Success Response This method does not return a value directly upon completion. Success or failure is communicated via the `completionHandler`. ``` -------------------------------- ### Metadata Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html An array of AVMetadataItem objects to be included in the exported media. ```swift public var metadata: [AVMetadataItem]? ``` -------------------------------- ### AudioMix Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Enables audio mixing and setting parameters for the export session. ```swift public var audioMix: AVAudioMix? ``` -------------------------------- ### Progress Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Indicates the progress of the export session as a float value between 0 and 1. ```swift public var progress: Float { get } ``` -------------------------------- ### Default Initializer Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html The default initializer for the NextLevelSessionExporter class. ```swift public override init() ``` -------------------------------- ### ExpectsMediaDataInRealTime Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Indicates whether the export session should expect media data in real time. Useful for live streaming scenarios. ```swift public var expectsMediaDataInRealTime: Bool ``` -------------------------------- ### OutputFileType Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Defines the type of the output file using a UTI string. ```swift public var outputFileType: AVFileType? ``` -------------------------------- ### NextLevelSessionExporter Export Methods Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Covers the methods for initiating, managing, and canceling export operations, including completion and progress handlers. ```APIDOC ## NextLevelSessionExporter Export Methods ### export(renderHandler:progressHandler:completionHandler:) Initiates an export session. Throws: Failure indication thrown when an error has occurred during export. #### Parameters - **renderHandler** (`RenderHandler?`): Handler for frame processing. - **progressHandler** (`ProgressHandler?`): Handler called with the export progress. - **completionHandler** (`CompletionHandler?`): Handler called when an export session completes. ### cancelExport() Cancels any export in progress. ``` -------------------------------- ### NextLevelSessionExporter Properties Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Provides details on the configurable properties of the NextLevelSessionExporter, including input asset, video composition, output settings, and more. ```APIDOC ## NextLevelSessionExporter Properties ### asset Input asset for export, provided when initialized. - **Type**: `AVAsset?` ### videoComposition Enables video composition and parameters for the session. - **Type**: `AVVideoComposition?` ### audioMix Enables audio mixing and parameters for the session. - **Type**: `AVAudioMix?` ### outputURL Output file location for the session. - **Type**: `URL?` ### outputFileType Output file type. UTI string defined in `AVMediaFormat.h`. - **Type**: `AVFileType?` ### timeRange Time range or limit of an export from `kCMTimeZero` to `kCMTimePositiveInfinity`. - **Type**: `CMTimeRange` ### expectsMediaDataInRealTime Indicates if an export session should expect media data in real time. - **Type**: `Bool` ### optimizeForNetworkUse Indicates if an export should be optimized for network use. - **Type**: `Bool` ### metadata Metadata to be added to an export. - **Type**: `[AVMetadataItem]?` ### videoInputConfiguration Video input configuration dictionary, using keys defined in ``. - **Type**: `[String : Any]?` ### videoOutputConfiguration Video output configuration dictionary, using keys defined in ``. - **Type**: `[String : Any]?` ### audioOutputConfiguration Audio output configuration dictionary, using keys defined in ``. - **Type**: `[String : Any]?` ### status Export session status state. - **Type**: `AVAssetExportSession.Status { get }` ### progress Session exporting progress from 0 to 1. - **Type**: `Float { get }` ``` -------------------------------- ### TimeRange Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Sets the time range for the export, limiting the duration of the exported media. ```swift public var timeRange: CMTimeRange ``` -------------------------------- ### NextLevelSessionExporterError Description Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Enums/NextLevelSessionExporterError.html Provides a human-readable string representation of the error. ```swift public var description: String { get } ``` -------------------------------- ### AVAsset Declaration Source: https://nextlevel.github.io/NextLevelSessionExporter/Extensions.html Shows the declaration of the AVAsset class in Swift. This is a fundamental class for working with media assets. ```swift class AVAsset : NSObject, NSCopying, AVAsynchronousKeyValueLoading ``` -------------------------------- ### OptimizeForNetworkUse Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Determines if the export should be optimized for network streaming, potentially affecting file structure and metadata. ```swift public var optimizeForNetworkUse: Bool ``` -------------------------------- ### Status Property Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Provides the current status of the export session, such as 'exporting', 'completed', or 'failed'. ```swift public var status: AVAssetExportSession.Status { get } ``` -------------------------------- ### RenderHandler Type Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Defines the type for a render handler, used for frame-by-frame processing during export. ```swift public typealias RenderHandler = (_ renderFrame: CVPixelBuffer, _ presentationTime: CMTime, _ resultingBuffer: CVPixelBuffer) -> Void ``` -------------------------------- ### Declare NextLevelSessionExporterErrorDomain Source: https://nextlevel.github.io/NextLevelSessionExporter/Global%20Variables.html Declares the global constant `NextLevelSessionExporterErrorDomain` which represents the error domain for session export operations. ```swift public let NextLevelSessionExporterErrorDomain: String ``` -------------------------------- ### NextLevelSessionExporter Class Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes.html The NextLevelSessionExporter class is responsible for exporting and transcoding media. It is declared as an open class inheriting from NSObject. ```APIDOC ## NextLevelSessionExporter ### Description Provides functionality for exporting and transcoding media assets. This class is designed to be used directly by developers to manage media output. ### Declaration Swift ```swift open class NextLevelSessionExporter : NSObject ``` ``` -------------------------------- ### CompletionHandler Type Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Defines the type for the completion handler, which is called when an export finishes. It returns a Result with either the final status or an Error. ```swift public typealias CompletionHandler = (Swift.Result) -> Void ``` -------------------------------- ### ProgressHandler Type Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Defines the type for a progress handler, which is called periodically to report the export progress. ```swift public typealias ProgressHandler = (_ progress: Float) -> Void ``` -------------------------------- ### NextLevelSessionExporterError Writing Failure Case Source: https://nextlevel.github.io/NextLevelSessionExporter/Enums/NextLevelSessionExporterError.html Represents an error that occurs while writing data during the session export process. ```swift case writingFailure ``` -------------------------------- ### NextLevelSessionExporterError Reading Failure Case Source: https://nextlevel.github.io/NextLevelSessionExporter/Enums/NextLevelSessionExporterError.html Represents an error that occurs while reading data during the session export process. ```swift case readingFailure ``` -------------------------------- ### NextLevelSessionExporterError Cancelled Case Source: https://nextlevel.github.io/NextLevelSessionExporter/Enums/NextLevelSessionExporterError.html Represents an error indicating that the session export process was cancelled. ```swift case cancelled ``` -------------------------------- ### CancelExport Method Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes/NextLevelSessionExporter.html Stops any ongoing export operation immediately. ```swift public func cancelExport() ``` -------------------------------- ### NextLevelSessionExporter Class Declaration Source: https://nextlevel.github.io/NextLevelSessionExporter/Classes.html Declaration of the NextLevelSessionExporter class. This class is available globally and inherits from NSObject. ```swift open class NextLevelSessionExporter : NSObject ``` -------------------------------- ### NextLevelSessionExporterError Enum Declaration Source: https://nextlevel.github.io/NextLevelSessionExporter/Enums.html Declaration of the NextLevelSessionExporterError enumeration, which conforms to Error and CustomStringConvertible protocols. ```swift public enum NextLevelSessionExporterError : Error, CustomStringConvertible ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.