From 8a10bea08781a67496a9c1c1de91b43c653eb3d6 Mon Sep 17 00:00:00 2001 From: skyfe79 Date: Mon, 8 Apr 2024 11:34:07 +0900 Subject: [PATCH] rename AVAssetEditContext to AVComposeContext --- Sources/core/AVEditContext.swift | 6 +++--- Sources/core/AVExporter.swift | 4 ++-- Sources/operations/AVOperation.swift | 6 +++--- Sources/operations/CropOperation.swift | 8 ++++---- Sources/operations/ExtractAudioOperation.swift | 6 +++--- Sources/operations/ExtractVideoOperation.swift | 8 ++++---- Sources/operations/GenerateImagesOperation.swift | 4 ++-- Sources/operations/ImagesToVideoOperation.swift | 4 ++-- Sources/operations/MergeOperation.swift | 6 +++--- Sources/operations/OverlayImageOperation.swift | 6 +++--- Sources/operations/OverlaySoundOperation.swift | 6 +++--- Sources/operations/OverlayTextOperation.swift | 6 +++--- Sources/operations/RotateOperation.swift | 6 +++--- Sources/operations/SpeedOperation.swift | 6 +++--- Sources/operations/SplitOperation.swift | 4 ++-- 15 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Sources/core/AVEditContext.swift b/Sources/core/AVEditContext.swift index 9fb6ee8..32c6ff3 100644 --- a/Sources/core/AVEditContext.swift +++ b/Sources/core/AVEditContext.swift @@ -1,9 +1,9 @@ import AVFoundation -/// A context for editing `AVAsset` instances, encapsulating composition, video composition, and audio mix. +/// A context for composing `AVAsset` instances, encapsulating composition, video composition, and audio mix. /// /// This class provides a structured way to manage the components required for editing an `AVAsset`, such as combining multiple assets, applying video and audio effects, and exporting the final composition. -class AVAssetEditContext { +class AVComposeContext { /// The composition of assets. /// /// This property holds the `AVComposition` object that represents the combined assets used in the editing context. @@ -19,7 +19,7 @@ class AVAssetEditContext { /// This optional property holds an `AVAudioMix` object, which defines how audio tracks are mixed and processed. It can include parameters for applying audio effects, volume adjustments, and other audio manipulations. let audioMix: AVAudioMix? - /// Initializes a new `AVAssetEditContext`. + /// Initializes a new `AVComposeContext`. /// /// - Parameters: /// - composition: An `AVComposition` object representing the combined assets. diff --git a/Sources/core/AVExporter.swift b/Sources/core/AVExporter.swift index 7da0659..720cb24 100644 --- a/Sources/core/AVExporter.swift +++ b/Sources/core/AVExporter.swift @@ -3,11 +3,11 @@ import AVFoundation /// A class responsible for exporting AV assets. class AVExporter { /// The editing context containing the asset to be exported. - private let editContext: AVAssetEditContext + private let editContext: AVComposeContext /// Initializes a new exporter with the given editing context. /// - Parameter editContext: The context containing the asset to be exported. - init(editContext: AVAssetEditContext) { + init(editContext: AVComposeContext) { self.editContext = editContext } diff --git a/Sources/operations/AVOperation.swift b/Sources/operations/AVOperation.swift index d8b18d4..af9cc33 100644 --- a/Sources/operations/AVOperation.swift +++ b/Sources/operations/AVOperation.swift @@ -1,9 +1,9 @@ /// A protocol that defines an asynchronous operation on an audiovisual asset. /// -/// Conforming types to `AVOperation` are responsible for performing operations that may include editing, processing, or analyzing audiovisual content. The result of the operation is an optional `AVAssetEditContext` which encapsulates the changes made to the asset. +/// Conforming types to `AVOperation` are responsible for performing operations that may include editing, processing, or analyzing audiovisual content. The result of the operation is an optional `AVComposeContext` which encapsulates the changes made to the asset. /// /// - Throws: An error if the operation cannot be completed. -/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. +/// - Returns: An optional `AVComposeContext` object representing the result of the operation. protocol AVOperation { - func run() async throws -> AVAssetEditContext? + func run() async throws -> AVComposeContext? } \ No newline at end of file diff --git a/Sources/operations/CropOperation.swift b/Sources/operations/CropOperation.swift index e3faf33..c69c0c0 100644 --- a/Sources/operations/CropOperation.swift +++ b/Sources/operations/CropOperation.swift @@ -21,14 +21,14 @@ class CropOperation: AVOperation { /// Runs the crop operation asynchronously. /// - /// This method creates a composition and a video composition, then returns an `AVAssetEditContext` containing these compositions. + /// This method creates a composition and a video composition, then returns an `AVComposeContext` containing these compositions. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let composition = await createComposition() let videoComposition = await createVideoComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoComposition) + return AVComposeContext(composition: composition, videoComposition: videoComposition) } /// Creates an `AVComposition` from the asset source. diff --git a/Sources/operations/ExtractAudioOperation.swift b/Sources/operations/ExtractAudioOperation.swift index e3b1ce5..56fc23e 100644 --- a/Sources/operations/ExtractAudioOperation.swift +++ b/Sources/operations/ExtractAudioOperation.swift @@ -19,10 +19,10 @@ class ExtractAudioOperation: AVOperation { /// This method creates an `AVComposition` containing only the audio track of the source asset. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let composition = await createComposition() - return AVAssetEditContext(composition: composition) + return AVComposeContext(composition: composition) } /// Asynchronously creates an `AVComposition` with the audio track of the source asset. diff --git a/Sources/operations/ExtractVideoOperation.swift b/Sources/operations/ExtractVideoOperation.swift index 83b056f..163af19 100644 --- a/Sources/operations/ExtractVideoOperation.swift +++ b/Sources/operations/ExtractVideoOperation.swift @@ -16,14 +16,14 @@ class ExtractVideoOperation: AVOperation { /// Runs the video extraction operation asynchronously. /// - /// This method creates an `AVComposition` and an `AVVideoComposition`, then returns an `AVAssetEditContext` containing these compositions. + /// This method creates an `AVComposition` and an `AVVideoComposition`, then returns an `AVComposeContext` containing these compositions. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let composition = await createComposition() let videoComposition = await createVideoComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoComposition) + return AVComposeContext(composition: composition, videoComposition: videoComposition) } /// Asynchronously creates an `AVComposition` with the video track of the source asset. diff --git a/Sources/operations/GenerateImagesOperation.swift b/Sources/operations/GenerateImagesOperation.swift index 4a9bac6..26ba587 100644 --- a/Sources/operations/GenerateImagesOperation.swift +++ b/Sources/operations/GenerateImagesOperation.swift @@ -33,9 +33,9 @@ class GenerateImagesOperation: AVOperation { /// This method generates images from the source asset at the specified times or at intervals defined by `stride`. The generated images are saved to the folder specified by `outputURL`. /// /// - Throws: An error if neither times nor stride are provided. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. Currently, this method always returns `nil`. + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. Currently, this method always returns `nil`. @discardableResult - func run() async throws -> AVAssetEditContext? { + func run() async throws -> AVComposeContext? { guard times.isEmpty == false || stride > 0 else { throw "Either times or stride must be provided" } diff --git a/Sources/operations/ImagesToVideoOperation.swift b/Sources/operations/ImagesToVideoOperation.swift index 7e901ad..58c65eb 100644 --- a/Sources/operations/ImagesToVideoOperation.swift +++ b/Sources/operations/ImagesToVideoOperation.swift @@ -42,10 +42,10 @@ class ImagesToVideoOperation: AVOperation { /// Executes the operation to generate a video from the images. /// - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. Currently, this method always returns `nil`. + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. Currently, this method always returns `nil`. /// - Throws: An error if the image size cannot be determined or the video cannot be written. @discardableResult - func run() async throws -> AVAssetEditContext? { + func run() async throws -> AVComposeContext? { try figureoutImageSize() guard imageSize != .zero else { throw NSError(domain: "ImagesToVideoOperation", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to determine image size."]) diff --git a/Sources/operations/MergeOperation.swift b/Sources/operations/MergeOperation.swift index 0c9439b..27da82e 100644 --- a/Sources/operations/MergeOperation.swift +++ b/Sources/operations/MergeOperation.swift @@ -20,8 +20,8 @@ class MergeOperation: AVOperation { /// This method reads all files from the input directory, sorts them, and merges their audio and video tracks into a single composition. It also creates a video composition to ensure consistent frame rate across the merged video. /// /// - Throws: An error if the files cannot be read or the merge operation fails. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the merge operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the merge operation. + func run() async throws -> AVComposeContext? { // Retrieve and sort files from the input directory. let files = try FileManager.default.contentsOfDirectory(at: inputURL, includingPropertiesForKeys: nil) let sortedFiles = files.sorted { $0.lastPathComponent < $1.lastPathComponent } @@ -57,6 +57,6 @@ class MergeOperation: AVOperation { videoComposition.frameDuration = CMTime(value: 1, timescale: 30) // Return the editing context containing the merged composition and video composition. - return AVAssetEditContext(composition: composition, videoComposition: videoComposition) + return AVComposeContext(composition: composition, videoComposition: videoComposition) } } diff --git a/Sources/operations/OverlayImageOperation.swift b/Sources/operations/OverlayImageOperation.swift index f35167a..4207b3a 100644 --- a/Sources/operations/OverlayImageOperation.swift +++ b/Sources/operations/OverlayImageOperation.swift @@ -31,10 +31,10 @@ class OverlayImageOperation: AVOperation { /// This method creates a composition and a video composition, then overlays the specified image onto the video track of the asset source. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let (composition, videoComposition) = await createComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoComposition) + return AVComposeContext(composition: composition, videoComposition: videoComposition) } /// Creates a composition and a video composition for the overlay operation. diff --git a/Sources/operations/OverlaySoundOperation.swift b/Sources/operations/OverlaySoundOperation.swift index 9bdadc5..b3bffd8 100644 --- a/Sources/operations/OverlaySoundOperation.swift +++ b/Sources/operations/OverlaySoundOperation.swift @@ -21,10 +21,10 @@ class OverlaySoundOperation: AVOperation { /// Executes the overlay operation asynchronously. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let (composition, videoComposition, audioMix) = await createComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoComposition, audioMix: audioMix) + return AVComposeContext(composition: composition, videoComposition: videoComposition, audioMix: audioMix) } /// Creates a composition and optionally an audio mix for the overlay operation. diff --git a/Sources/operations/OverlayTextOperation.swift b/Sources/operations/OverlayTextOperation.swift index 24191e1..c4f1728 100644 --- a/Sources/operations/OverlayTextOperation.swift +++ b/Sources/operations/OverlayTextOperation.swift @@ -30,10 +30,10 @@ class OverlayTextOperation: AVOperation { /// Executes the overlay operation asynchronously. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let (composition, videoComposition) = await createComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoComposition) + return AVComposeContext(composition: composition, videoComposition: videoComposition) } /// Creates a composition and a video composition for the overlay operation. diff --git a/Sources/operations/RotateOperation.swift b/Sources/operations/RotateOperation.swift index 64c2d3a..c8e449e 100644 --- a/Sources/operations/RotateOperation.swift +++ b/Sources/operations/RotateOperation.swift @@ -22,11 +22,11 @@ class RotateOperation: AVOperation { /// Executes the rotation operation asynchronously. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the rotation operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the rotation operation. + func run() async throws -> AVComposeContext? { let composition = await createComposition() let videoComposition = await createVideoComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoComposition) + return AVComposeContext(composition: composition, videoComposition: videoComposition) } /// Creates a composition for the rotation operation. diff --git a/Sources/operations/SpeedOperation.swift b/Sources/operations/SpeedOperation.swift index 5d92b76..c69eb9d 100644 --- a/Sources/operations/SpeedOperation.swift +++ b/Sources/operations/SpeedOperation.swift @@ -21,10 +21,10 @@ class SpeedOperation: AVOperation { /// Executes the speed adjustment operation asynchronously. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation. + func run() async throws -> AVComposeContext? { let (composition, videoCompositon) = await createComposition() - return AVAssetEditContext(composition: composition, videoComposition: videoCompositon) + return AVComposeContext(composition: composition, videoComposition: videoCompositon) } /// Creates a composition and a video composition for the speed adjustment operation. diff --git a/Sources/operations/SplitOperation.swift b/Sources/operations/SplitOperation.swift index 22a5045..d432bcc 100644 --- a/Sources/operations/SplitOperation.swift +++ b/Sources/operations/SplitOperation.swift @@ -29,8 +29,8 @@ class SplitOperation: AVOperation { /// This method creates a directory at the output URL (if it doesn't already exist), calculates the time ranges for each segment based on the specified duration, and exports each segment to the output URL. /// /// - Throws: An error if the operation cannot be completed. - /// - Returns: An optional `AVAssetEditContext` object representing the result of the operation, which is `nil` in this case as the operation does not modify the asset context. - func run() async throws -> AVAssetEditContext? { + /// - Returns: An optional `AVComposeContext` object representing the result of the operation, which is `nil` in this case as the operation does not modify the asset context. + func run() async throws -> AVComposeContext? { do { try FileManager.default.createDirectory(at: outputURL, withIntermediateDirectories: true, attributes: nil) let ranges = CMTimeRange.stride(range: assetSource.duration.range, by: CMTimeValue(duration))