sindresorhus / Gifski

🌈 Convert videos to high-quality GIFs on your Mac
https://sindresorhus.com/gifski
MIT License
7.79k stars 295 forks source link

Remove use of `generateCGImagesAsynchronously` #229

Closed sindresorhus closed 8 months ago

sindresorhus commented 3 years ago

The API has been a constant PITA and it's super buggy.

Instead, we should use AVAssetReader and readerOutput.copyNextSampleBuffer().

I think it would be best to wrap up all the logic into a similar interface as generateCGImagesAsynchronously, but instead of accepting time points, it would accept FPS.

Some inspiration here: https://github.com/twostraws/ControlRoom/blob/659c5d5f3ab982ea54c9346aec9b700c147112b5/ControlRoom/Extensions/AVAssetToGIF.swift


This issue requires advanced Swift knowledge.


You can use this to get the CGImage from the pixel buffer:

import VideoToolbox

extension CVPixelBuffer {
    var cgImage: CGImage? {
        var cgImage: CGImage?
        VTCreateCGImageFromCVPixelBuffer(self, options: nil, imageOut: &cgImage)
        return cgImage
    }
}