Skip to content

Commit

Permalink
Revert e47642d (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 6, 2021
1 parent 906fcaf commit 45bf373
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions Gifski/Utilities.swift
Expand Up @@ -342,12 +342,9 @@ extension AVAssetImageGenerator {
var completedCount = 0
var decodeFailureFrameCount = 0

generateCGImagesAsynchronously(forTimes: times) { [weak self] requestedTime, image, actualTime, result, error in
guard let self = self else {
return
}

if (Double(decodeFailureFrameCount) / Double(totalCount)) > 0.8 {
generateCGImagesAsynchronously(forTimes: times) { requestedTime, image, actualTime, result, error in
let successFrameCount = totalCount - decodeFailureFrameCount
if successFrameCount <= 2 {
completionHandler(.failure(NSError.appError("\(decodeFailureFrameCount) of \(totalCount) frames failed to decode. This is a bug in macOS. We are looking into workarounds.")))
return
}
Expand Down Expand Up @@ -378,30 +375,11 @@ extension AVAssetImageGenerator {
break
}

// macOS 11 (still an issue in macOS 11.1) started throwing “decode failed” error for some frames in screen recordings. As a workaround, we ignore these. We throw an error if more than 50% of the frames could not be decoded.
// macOS 11 (still an issue in macOS 11.2) started throwing “decode failed” error for some frames in screen recordings. As a workaround, we ignore these.
if error.code == .decodeFailed {
var newActualTime = CMTime.zero
if let image = try? self.copyCGImage(at: requestedTime, actualTime: &newActualTime) {
completedCount += 1

completionHandler(
.success(
CompletionHandlerResult(
image: image,
requestedTime: requestedTime,
actualTime: newActualTime,
completedCount: completedCount,
totalCount: totalCount,
isFinished: completedCount == totalCount
)
)
)
} else {
decodeFailureFrameCount += 1
totalCount -= 1
Crashlytics.recordNonFatalError(error: error, userInfo: ["requestedTime": requestedTime.seconds])
}

decodeFailureFrameCount += 1
totalCount -= 1
Crashlytics.recordNonFatalError(error: error, userInfo: ["requestedTime": requestedTime.seconds])
break
}
}
Expand Down

0 comments on commit 45bf373

Please sign in to comment.