Skip to content

Commit bd88be4

Browse files
committed
Use proportional width/height if only 1 specified, default to 2x if
neither specified closes #3
1 parent 034d198 commit bd88be4

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/MetalFXUpscale.xcscheme renamed to .swiftpm/xcode/xcshareddata/xcschemes/fx-upscale.xcscheme

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "MetalFXUpscale"
18-
BuildableName = "MetalFXUpscale"
19-
BlueprintName = "MetalFXUpscale"
17+
BlueprintIdentifier = "fx-upscale"
18+
BuildableName = "fx-upscale"
19+
BlueprintName = "fx-upscale"
2020
ReferencedContainer = "container:">
2121
</BuildableReference>
2222
</BuildActionEntry>
@@ -43,9 +43,9 @@
4343
runnableDebuggingMode = "0">
4444
<BuildableReference
4545
BuildableIdentifier = "primary"
46-
BlueprintIdentifier = "MetalFXUpscale"
47-
BuildableName = "MetalFXUpscale"
48-
BlueprintName = "MetalFXUpscale"
46+
BlueprintIdentifier = "fx-upscale"
47+
BuildableName = "fx-upscale"
48+
BlueprintName = "fx-upscale"
4949
ReferencedContainer = "container:">
5050
</BuildableReference>
5151
</BuildableProductRunnable>
@@ -60,9 +60,9 @@
6060
runnableDebuggingMode = "0">
6161
<BuildableReference
6262
BuildableIdentifier = "primary"
63-
BlueprintIdentifier = "MetalFXUpscale"
64-
BuildableName = "MetalFXUpscale"
65-
BlueprintName = "MetalFXUpscale"
63+
BlueprintIdentifier = "fx-upscale"
64+
BuildableName = "fx-upscale"
65+
BlueprintName = "fx-upscale"
6666
ReferencedContainer = "container:">
6767
</BuildableReference>
6868
</BuildableProductRunnable>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Metal-powered video upscaling
66

77
## Usage
88
```
9-
USAGE: fx-upscale <source-file> --width <destination-width> --height <destination-height>
9+
USAGE: fx-upscale <url> [--width <width>] [--height <height>]
1010
```
1111

1212
## Installation

Sources/FXUpscale.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import SwiftTUI
99
@main struct FXUpscale: AsyncParsableCommand {
1010
@Argument(help: "The video file to upscale", transform: URL.init(fileURLWithPath:)) var url: URL
1111

12-
@Option(help: "The output file width") var width: Int
13-
@Option(help: "The output file height") var height: Int
12+
@Option(help: "The output file width") var width: Int?
13+
@Option(help: "The output file height") var height: Int?
1414

1515
mutating func run() async throws {
1616
guard FileManager.default.fileExists(atPath: url.path) else {
@@ -26,16 +26,27 @@ import SwiftTUI
2626
throw ValidationError("File already exists at \(outputURL.path(percentEncoded: false))")
2727
}
2828

29-
guard width <= 7680, height <= 7680 else {
30-
throw ValidationError("Maximum supported width/height: 7680")
31-
}
32-
3329
let asset = AVAsset(url: url)
3430
guard let videoTrack = try await asset.loadTracks(withMediaType: .video).first else {
3531
throw ValidationError("Failed to get video track from input file")
3632
}
3733

3834
let inputSize = try await videoTrack.load(.naturalSize)
35+
36+
// 1. Use passed in width/height
37+
// 2. Use proportional width/height if only one is specified
38+
// 3. Default to 2x upscale
39+
40+
let width = width ??
41+
height.map { Int(inputSize.width * (CGFloat($0) / inputSize.height)) } ??
42+
Int(inputSize.width) * 2
43+
let height = height ??
44+
Int(inputSize.height * (CGFloat(width) / inputSize.width))
45+
46+
guard width <= 7680, height <= 7680 else {
47+
throw ValidationError("Maximum supported width/height: 7680")
48+
}
49+
3950
let outputSize = CGSize(width: width, height: height)
4051

4152
let videoComposition = AVMutableVideoComposition()

0 commit comments

Comments
 (0)