Skip to content

Commit 46d5dad

Browse files
Add option to choose output codec
1 parent 59f4660 commit 46d5dad

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Sources/fx-upscale/FXUpscale.swift

+17-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Upscaling
1111

1212
@Option(name: .shortAndLong, help: "The output file width") var width: Int?
1313
@Option(name: .shortAndLong, help: "The output file height") var height: Int?
14+
@Option(name: .shortAndLong, help: "Output codec: 'hevc', 'prores', or 'h264' (default: hevc)") var codec: String = "hevc"
1415

1516
mutating func run() async throws {
1617
guard ["mov", "m4v", "mp4"].contains(url.pathExtension.lowercased()) else {
@@ -51,21 +52,33 @@ import Upscaling
5152
}
5253

5354
let outputSize = CGSize(width: width, height: height)
55+
let outputCodec: AVVideoCodecType? = {
56+
switch codec.lowercased() {
57+
case "prores": return .proRes422
58+
case "h264": return .h264
59+
default: return .hevc
60+
}
61+
}()
5462

55-
let convertToProRes = (outputSize.width * outputSize.height) > (3840 * 2160) &&
56-
!(formatDescription?.videoCodecType?.isProRes ?? false)
63+
// Through anecdotal tests anything beyond 14.5K fails to encode for anything other than ProRes
64+
let convertToProRes = (outputSize.width * outputSize.height) > (14500 * 8156)
65+
66+
if (convertToProRes) {
67+
CommandLine.info("Forced ProRes conversion due to output size being larger than 14.5K (will fail otherwise)")
68+
}
5769

5870
let exportSession = UpscalingExportSession(
5971
asset: asset,
60-
outputCodec: convertToProRes ? .proRes422 : nil,
72+
outputCodec: convertToProRes ? .proRes422 : outputCodec,
6173
preferredOutputURL: url.renamed { "\($0) Upscaled" },
6274
outputSize: outputSize,
6375
creator: ProcessInfo.processInfo.processName
6476
)
6577

6678
CommandLine.info([
6779
"Upscaling from \(Int(inputSize.width))x\(Int(inputSize.height)) ",
68-
"to \(Int(outputSize.width))x\(Int(outputSize.height)) "
80+
"to \(Int(outputSize.width))x\(Int(outputSize.height)) ",
81+
"using codec: \(outputCodec?.rawValue ?? "hevc")"
6982
].joined())
7083
ProgressBar.start(progress: exportSession.progress)
7184
try await exportSession.export()

0 commit comments

Comments
 (0)