Skip to content

Commit decc837

Browse files
authored
Update progress on main thread (#23)
1 parent b4ead0f commit decc837

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

.swiftformat

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
--swiftversion 5.9
12
--enable blankLineAfterImports
23
--enable blankLinesBetweenImports
34
--enable blockComments
@@ -14,7 +15,8 @@
1415
--ifdef no-indent
1516
--funcattributes same-line
1617
--typeattributes same-line
17-
--varattributes same-line
18+
--computedvarattrs same-line
19+
--storedvarattrs same-line
1820
--ranges no-space
1921
--header strip
2022
--selfrequired log,debug,info,notice,warning,trace,error,critical,fault

Sources/Upscaling/CoreImage/UpscalingFilter.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import MetalFX
99
public class UpscalingFilter: CIFilter {
1010
// MARK: Public
1111

12-
public var inputImage: CIImage?
13-
public var outputSize: CGSize?
14-
1512
override public var outputImage: CIImage? {
1613
#if canImport(MetalFX)
1714
guard let device, let inputImage, let outputSize else { return nil }
@@ -49,6 +46,9 @@ public class UpscalingFilter: CIFilter {
4946
#endif
5047
}
5148

49+
public var inputImage: CIImage?
50+
public var outputSize: CGSize?
51+
5252
// MARK: Private
5353

5454
private let device = MTLCreateSystemDefaultDevice()

Sources/Upscaling/UpscalingExportSession.swift

+13-9
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ public class UpscalingExportSession {
5151
throw Error.outputURLAlreadyExists
5252
}
5353

54-
let outputFileType: AVFileType = {
55-
switch outputURL.pathExtension.lowercased() {
56-
case "mov": return .mov
57-
case "m4v": return .m4v
58-
default: return .mp4
59-
}
60-
}()
54+
let outputFileType: AVFileType = switch outputURL.pathExtension.lowercased() {
55+
case "mov": .mov
56+
case "m4v": .m4v
57+
default: .mp4
58+
}
6159

6260
let assetWriter = try AVAssetWriter(outputURL: outputURL, fileType: outputFileType)
6361
assetWriter.metadata = try await asset.load(.metadata)
@@ -383,7 +381,10 @@ public class UpscalingExportSession {
383381
while assetWriterInput.isReadyForMoreMediaData {
384382
if let nextSampleBuffer = assetReaderOutput.copyNextSampleBuffer() {
385383
if nextSampleBuffer.presentationTimeStamp.isNumeric {
386-
progress.completedUnitCount = Int64(nextSampleBuffer.presentationTimeStamp.seconds)
384+
let timestamp = Int64(nextSampleBuffer.presentationTimeStamp.seconds)
385+
DispatchQueue.main.async {
386+
progress.completedUnitCount = timestamp
387+
}
387388
}
388389
if let imageBuffer = nextSampleBuffer.imageBuffer {
389390
let upscaledImageBuffer = upscaler.upscale(
@@ -433,7 +434,10 @@ public class UpscalingExportSession {
433434
while assetWriterInput.isReadyForMoreMediaData {
434435
if let nextSampleBuffer = assetReaderOutput.copyNextSampleBuffer() {
435436
if nextSampleBuffer.presentationTimeStamp.isNumeric {
436-
progress.completedUnitCount = Int64(nextSampleBuffer.presentationTimeStamp.seconds)
437+
let timestamp = Int64(nextSampleBuffer.presentationTimeStamp.seconds)
438+
DispatchQueue.main.async {
439+
progress.completedUnitCount = timestamp
440+
}
437441
}
438442
if let taggedBuffers = nextSampleBuffer.taggedBuffers {
439443
let leftEyeBuffer = taggedBuffers.first(where: {

Sources/fx-upscale/FXUpscale.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ import Upscaling
5252
}
5353

5454
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-
}()
55+
let outputCodec: AVVideoCodecType? = switch codec.lowercased() {
56+
case "prores": .proRes422
57+
case "h264": .h264
58+
default: .hevc
59+
}
6260

6361
// Through anecdotal tests anything beyond 14.5K fails to encode for anything other than ProRes
6462
let convertToProRes = (outputSize.width * outputSize.height) > (14500 * 8156)
6563

66-
if (convertToProRes) {
64+
if convertToProRes {
6765
CommandLine.info("Forced ProRes conversion due to output size being larger than 14.5K (will fail otherwise)")
6866
}
6967

0 commit comments

Comments
 (0)