Skip to content

Commit

Permalink
rename movie merger
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo committed Mar 20, 2021
1 parent 4ef4046 commit f295c73
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import Foundation
import AVFoundation

public final class MovieSegmentsMerger {
public final class AssetMerger {

public enum Error: LocalizedError {
case noSegments
case noAssets
case cannotCreateExportSession
case unsupportedFileType
public var errorDescription: String? {
switch self {
case .noSegments:
return "No segments to merge."
case .noAssets:
return "No assets to merge."
case .cannotCreateExportSession:
return "Cannot create export session."
case .unsupportedFileType:
Expand All @@ -26,17 +26,17 @@ public final class MovieSegmentsMerger {
}
}

public static func merge(_ segments: [URL], to url: URL, completion: @escaping (Swift.Error?) -> Void) {
if segments.isEmpty {
completion(Error.noSegments)
public static func merge(_ assets: [URL], to url: URL, completion: @escaping (Swift.Error?) -> Void) {
if assets.isEmpty {
completion(Error.noAssets)
return
}
let composition = AVMutableComposition()
var current: CMTime = .zero
var firstSegmentTransform: CGAffineTransform = .identity

var isFirstSegmentTransformSet = false
for segment in segments {
for segment in assets {
let asset = AVURLAsset(url: segment, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
if !isFirstSegmentTransformSet, let videoTrack = asset.tracks(withMediaType: .video).first {
firstSegmentTransform = videoTrack.preferredTransform
Expand Down

0 comments on commit f295c73

Please sign in to comment.