another.im-ios/ConversationsClassic/Helpers/AVAsset+Thumbnail.swift
fmodf b3b3b3aef7 mv-experiment (#1)
Reviewed-on: narayana/conversations-classic-ios#1
Co-authored-by: fmodf <fmodf.ios@gmail.com>
Co-committed-by: fmodf <fmodf.ios@gmail.com>
2024-09-03 15:13:58 +00:00

17 lines
623 B
Swift

import AVFoundation
import UIKit
extension AVAsset {
func generateVideoThumbnail(_ size: CGSize) async throws -> UIImage {
try await Task {
let assetImgGenerate = AVAssetImageGenerator(asset: self)
assetImgGenerate.appliesPreferredTrackTransform = true
let time = CMTimeMakeWithSeconds(Float64(1), preferredTimescale: 600)
let cgImage = try assetImgGenerate.copyCGImage(at: time, actualTime: nil)
let image = UIImage(cgImage: cgImage)
let result = try await image.scaleAndCropImage(size)
return result
}.value
}
}