mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Use asynchronous thumbnail generation for round videos
This commit is contained in:
parent
bcfb9a969d
commit
2bbb9fd1f3
@ -1508,18 +1508,36 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
|
||||
let dimensions = PixelDimensions(width: 400, height: 400)
|
||||
|
||||
var thumbnailImage = video.thumbnail
|
||||
let thumbnailImage: Signal<UIImage, NoError>
|
||||
if startTime > 0.0 {
|
||||
thumbnailImage = Signal { subscriber in
|
||||
let composition = composition(with: results)
|
||||
let imageGenerator = AVAssetImageGenerator(asset: composition)
|
||||
imageGenerator.maximumSize = dimensions.cgSize
|
||||
imageGenerator.appliesPreferredTrackTransform = true
|
||||
|
||||
if let cgImage = try? imageGenerator.copyCGImage(at: CMTime(seconds: startTime, preferredTimescale: composition.duration.timescale), actualTime: nil) {
|
||||
thumbnailImage = UIImage(cgImage: cgImage)
|
||||
imageGenerator.generateCGImagesAsynchronously(forTimes: [NSValue(time: CMTime(seconds: startTime, preferredTimescale: composition.duration.timescale))], completionHandler: { _, image, _, _, _ in
|
||||
if let image {
|
||||
subscriber.putNext(UIImage(cgImage: image))
|
||||
} else {
|
||||
subscriber.putNext(video.thumbnail)
|
||||
}
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
|
||||
return ActionDisposable {
|
||||
imageGenerator.cancelAllCGImageGeneration()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
thumbnailImage = .single(video.thumbnail)
|
||||
}
|
||||
|
||||
let _ = (thumbnailImage
|
||||
|> deliverOnMainQueue).startStandalone(next: { [weak self] thumbnailImage in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
let values = MediaEditorValues(peerId: self.context.account.peerId, originalDimensions: dimensions, cropOffset: .zero, cropRect: CGRect(origin: .zero, size: dimensions.cgSize), cropScale: 1.0, cropRotation: 0.0, cropMirroring: false, cropOrientation: nil, gradientColors: nil, videoTrimRange: self.node.previewState?.trimRange, videoIsMuted: false, videoIsFullHd: false, videoIsMirrored: false, videoVolume: nil, additionalVideoPath: nil, additionalVideoIsDual: false, additionalVideoPosition: nil, additionalVideoScale: nil, additionalVideoRotation: nil, additionalVideoPositionChanges: [], additionalVideoTrimRange: nil, additionalVideoOffset: nil, additionalVideoVolume: nil, nightTheme: false, drawing: nil, entities: [], toolValues: [:], audioTrack: nil, audioTrackTrimRange: nil, audioTrackOffset: nil, audioTrackVolume: nil, audioTrackSamples: nil, qualityPreset: .videoMessage)
|
||||
|
||||
var resourceAdjustments: VideoMediaResourceAdjustments? = nil
|
||||
@ -1581,6 +1599,7 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
bubbleUpEmojiOrStickersets: []
|
||||
), silentPosting, scheduleTime)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
private var waitingForNextResult = false
|
||||
|
Loading…
x
Reference in New Issue
Block a user