From f531f40c084f3f0683eabbd851e2702ae2c3feb9 Mon Sep 17 00:00:00 2001 From: skyfe79 Date: Mon, 8 Apr 2024 11:47:50 +0900 Subject: [PATCH] rename editContext to composeContext --- Sources/commands/CropCommand.swift | 4 ++-- Sources/commands/ExtractAudioCommand.swift | 4 ++-- Sources/commands/ExtractVideoCommand.swift | 4 ++-- Sources/commands/MergeCommand.swift | 4 ++-- Sources/commands/OverlayImageCommand.swift | 4 ++-- Sources/commands/OverlaySoundCommand.swift | 4 ++-- Sources/commands/OverlayTextCommand.swift | 4 ++-- Sources/commands/RotateCommand.swift | 4 ++-- Sources/commands/SpeedCommand.swift | 4 ++-- Sources/core/AVExporter.swift | 14 +++++++------- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/commands/CropCommand.swift b/Sources/commands/CropCommand.swift index 537e14f..f892817 100644 --- a/Sources/commands/CropCommand.swift +++ b/Sources/commands/CropCommand.swift @@ -25,8 +25,8 @@ extension AVTools { print("naturalSize size: \(assetSource.naturalSize)") let cropOperation = CropOperation(assetSource: assetSource, cropRect: cropRect) - if let editContext = try await cropOperation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await cropOperation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/commands/ExtractAudioCommand.swift b/Sources/commands/ExtractAudioCommand.swift index df538ce..f02ac48 100644 --- a/Sources/commands/ExtractAudioCommand.swift +++ b/Sources/commands/ExtractAudioCommand.swift @@ -21,8 +21,8 @@ extension AVTools { print("naturalSize size: \(assetSource.naturalSize)") let operation = ExtractAudioOperation(assetSource: assetSource) - if let editContext = try await operation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await operation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output, outputFileType: .m4a, presetName: AVAssetExportPresetAppleM4A) } catch { diff --git a/Sources/commands/ExtractVideoCommand.swift b/Sources/commands/ExtractVideoCommand.swift index b741b87..d0ad89c 100644 --- a/Sources/commands/ExtractVideoCommand.swift +++ b/Sources/commands/ExtractVideoCommand.swift @@ -21,8 +21,8 @@ extension AVTools { print("naturalSize size: \(assetSource.naturalSize)") let operation = ExtractVideoOperation(assetSource: assetSource) - if let editContext = try await operation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await operation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/commands/MergeCommand.swift b/Sources/commands/MergeCommand.swift index 9ee63d7..7b7b3e7 100644 --- a/Sources/commands/MergeCommand.swift +++ b/Sources/commands/MergeCommand.swift @@ -16,8 +16,8 @@ extension AVTools { mutating func run() async throws { let mergeOperation = MergeOperation(inputURL: options.input) - if let editContext = try await mergeOperation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await mergeOperation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output, outputFileType: .mov, presetName: AVAssetExportPresetHighestQuality) } catch { diff --git a/Sources/commands/OverlayImageCommand.swift b/Sources/commands/OverlayImageCommand.swift index da86460..cc35c7d 100644 --- a/Sources/commands/OverlayImageCommand.swift +++ b/Sources/commands/OverlayImageCommand.swift @@ -30,8 +30,8 @@ extension AVTools { print("naturalSize size: \(assetSource.naturalSize)") let operation = OverlayImageOperation(assetSource: assetSource, overlayImage: image, start: start, duration: duration) - if let editContext = try await operation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await operation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/commands/OverlaySoundCommand.swift b/Sources/commands/OverlaySoundCommand.swift index dc6e0ec..66635c1 100644 --- a/Sources/commands/OverlaySoundCommand.swift +++ b/Sources/commands/OverlaySoundCommand.swift @@ -22,8 +22,8 @@ extension AVTools { mutating func run() async throws { try await assetSource.load() let overlaySoundOperation = OverlaySoundOperation(assetSource: assetSource, soundURL: sound) - if let editContext = try await overlaySoundOperation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await overlaySoundOperation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/commands/OverlayTextCommand.swift b/Sources/commands/OverlayTextCommand.swift index 5017a68..67ebc6b 100644 --- a/Sources/commands/OverlayTextCommand.swift +++ b/Sources/commands/OverlayTextCommand.swift @@ -29,8 +29,8 @@ extension AVTools { mutating func run() async throws { try await assetSource.load() let overlayTextOperation = OverlayTextOperation(assetSource: assetSource, text: text, fontSize: size, color: color) - if let editContext = try await overlayTextOperation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await overlayTextOperation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/commands/RotateCommand.swift b/Sources/commands/RotateCommand.swift index 7e1e99f..37f9da5 100644 --- a/Sources/commands/RotateCommand.swift +++ b/Sources/commands/RotateCommand.swift @@ -24,8 +24,8 @@ extension AVTools { print("naturalSize size: \(assetSource.naturalSize)") let rotateOperation = RotateOperation(assetSource: assetSource, angle: angle) - if let editContext = try await rotateOperation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await rotateOperation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/commands/SpeedCommand.swift b/Sources/commands/SpeedCommand.swift index f8eaa13..2577ff4 100644 --- a/Sources/commands/SpeedCommand.swift +++ b/Sources/commands/SpeedCommand.swift @@ -24,8 +24,8 @@ extension AVTools { mutating func run() async throws { try await assetSource.load() let speedOperation = SpeedOperation(assetSource: assetSource, speed: speed) - if let editContext = try await speedOperation.run() { - let exporter = AVExporter(editContext: editContext) + if let composeContext = try await speedOperation.run() { + let exporter = AVExporter(composeContext: composeContext) do { try await exporter.export(outputURL: options.output) } catch { diff --git a/Sources/core/AVExporter.swift b/Sources/core/AVExporter.swift index 720cb24..8834796 100644 --- a/Sources/core/AVExporter.swift +++ b/Sources/core/AVExporter.swift @@ -3,12 +3,12 @@ import AVFoundation /// A class responsible for exporting AV assets. class AVExporter { /// The editing context containing the asset to be exported. - private let editContext: AVComposeContext + private let composeContext: AVComposeContext /// Initializes a new exporter with the given editing context. - /// - Parameter editContext: The context containing the asset to be exported. - init(editContext: AVComposeContext) { - self.editContext = editContext + /// - Parameter composeContext: The context containing the asset to be exported. + init(composeContext: AVComposeContext) { + self.composeContext = composeContext } /// Exports the asset to the specified URL with the given settings. @@ -18,17 +18,17 @@ class AVExporter { /// - presetName: The preset name to use for the export. Defaults to `AVAssetExportPresetHighestQuality`. /// - Throws: An error if the export fails. func export(outputURL: URL, outputFileType: AVFileType = .mov, presetName: String = AVAssetExportPresetHighestQuality) async throws { - guard let exportSession = AVAssetExportSession(asset: editContext.composition, presetName: presetName) else { + guard let exportSession = AVAssetExportSession(asset: composeContext.composition, presetName: presetName) else { throw "Failed to create AVAssetExportSession" } exportSession.outputURL = outputURL exportSession.outputFileType = outputFileType // Apply video composition and audio mix if they exist. - if let videoComposition = editContext.videoComposition { + if let videoComposition = composeContext.videoComposition { exportSession.videoComposition = videoComposition } - if let audioMix = editContext.audioMix { + if let audioMix = composeContext.audioMix { exportSession.audioMix = audioMix } await exportSession.export()