Skip to content

Commit

Permalink
Apply video transforms, add MDItemCreator
Browse files Browse the repository at this point in the history
closes #8
  • Loading branch information
finnvoor committed Jan 17, 2024
1 parent f95c41f commit c3f3c69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
30 changes: 29 additions & 1 deletion Sources/Upscaling/UpscalingExportSession.swift
Expand Up @@ -8,11 +8,13 @@ public class UpscalingExportSession {
public init(
asset: AVAsset,
outputURL: URL,
outputSize: CGSize
outputSize: CGSize,
creator: String? = nil
) {
self.asset = asset
self.outputURL = outputURL
self.outputSize = outputSize
self.creator = creator
}

// MARK: Public
Expand All @@ -22,6 +24,7 @@ public class UpscalingExportSession {
public let asset: AVAsset
public private(set) var outputURL: URL
public let outputSize: CGSize
public let creator: String?

public func export() async throws {
if outputURL.pathExtension.lowercased() != "mov",
Expand Down Expand Up @@ -118,6 +121,11 @@ public class UpscalingExportSession {
}

let videoInput = AVAssetWriterInput(mediaType: .video, outputSettings: outputSettings)

// I would assume this should be adjusted for the new scale,
// but it seems to work fine...
videoInput.transform = try await track.load(.preferredTransform)

videoInput.expectsMediaDataInRealTime = false
if assetWriter.canAdd(videoInput) {
assetWriter.add(videoInput)
Expand Down Expand Up @@ -216,6 +224,26 @@ public class UpscalingExportSession {
}
}
} as Void

if let creator {
let value = try PropertyListSerialization.data(
fromPropertyList: creator,
format: .binary,
options: 0
)
_ = outputURL.withUnsafeFileSystemRepresentation { fileSystemPath in
value.withUnsafeBytes {
setxattr(
fileSystemPath,
"com.apple.metadata:kMDItemCreator",
$0.baseAddress,
value.count,
0,
0
)
}
}
}
}

// MARK: Private
Expand Down
3 changes: 2 additions & 1 deletion Sources/fx-upscale/FXUpscale.swift
Expand Up @@ -57,7 +57,8 @@ import Upscaling
let exportSession = UpscalingExportSession(
asset: asset,
outputURL: outputURL,
outputSize: outputSize
outputSize: outputSize,
creator: ProcessInfo.processInfo.processName
)

CommandLine.info([
Expand Down

0 comments on commit c3f3c69

Please sign in to comment.