How to choose best quality thumbnail from a video

106 Views Asked by At

Is there a way to generate a good quality thumbnail out of a video. This function I have below generates the first frame of the video as a thumbnail. The problem is usually the thumbnail is pixelated because it doesn't come from a stationary frame of the video. Is there a way to generate a thumbnail, so that the frame it chooses it from is not blurry, or is a good quality frame?

func getThumbnail(_ outputFileURL:URL) -> UIImage {
    let clip = AVURLAsset(url: outputFileURL)
    let imgGenerator = AVAssetImageGenerator(asset: clip)
    if let cgImage = try? imgGenerator.copyCGImage(
        at: CMTimeMake(0, 1), actualTime: nil) {
        let uiImage = UIImage(cgImage: cgImage)
        return uiImage
    } else {
        return UIImage(named: "default.png")!
    }
}
0

There are 0 best solutions below