Skip to content

Commit

Permalink
rename editContext to composeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfe79 committed Apr 8, 2024
1 parent 8a10bea commit f531f40
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Sources/commands/CropCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/ExtractAudioCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/ExtractVideoCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/MergeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/OverlayImageCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/OverlaySoundCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/OverlayTextCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/RotateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/commands/SpeedCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions Sources/core/AVExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down

0 comments on commit f531f40

Please sign in to comment.