@@ -11,6 +11,7 @@ import Upscaling
11
11
12
12
@Option ( name: . shortAndLong, help: " The output file width " ) var width : Int ?
13
13
@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 "
14
15
15
16
mutating func run( ) async throws {
16
17
guard [ " mov " , " m4v " , " mp4 " ] . contains ( url. pathExtension. lowercased ( ) ) else {
@@ -51,21 +52,33 @@ import Upscaling
51
52
}
52
53
53
54
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
+ } ( )
54
62
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
+ }
57
69
58
70
let exportSession = UpscalingExportSession (
59
71
asset: asset,
60
- outputCodec: convertToProRes ? . proRes422 : nil ,
72
+ outputCodec: convertToProRes ? . proRes422 : outputCodec ,
61
73
preferredOutputURL: url. renamed { " \( $0) Upscaled " } ,
62
74
outputSize: outputSize,
63
75
creator: ProcessInfo . processInfo. processName
64
76
)
65
77
66
78
CommandLine . info ( [
67
79
" 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 " ) "
69
82
] . joined ( ) )
70
83
ProgressBar . start ( progress: exportSession. progress)
71
84
try await exportSession. export ( )
0 commit comments