mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Various fixes
This commit is contained in:
parent
ccf6956beb
commit
b746fd85e0
@ -1470,8 +1470,10 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
return
|
||||
}
|
||||
|
||||
var startTime: Double = 0.0
|
||||
let finalDuration: Double
|
||||
if let trimRange = self.node.previewState?.trimRange {
|
||||
startTime = trimRange.lowerBound
|
||||
finalDuration = trimRange.upperBound - trimRange.lowerBound
|
||||
if finalDuration != duration {
|
||||
hasAdjustments = true
|
||||
@ -1480,6 +1482,18 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
finalDuration = duration
|
||||
}
|
||||
|
||||
var thumbnailImage = video.thumbnail
|
||||
if startTime > 0.0 {
|
||||
let composition = composition(with: results)
|
||||
let imageGenerator = AVAssetImageGenerator(asset: composition)
|
||||
imageGenerator.maximumSize = CGSize(width: 400, height: 400)
|
||||
imageGenerator.appliesPreferredTrackTransform = true
|
||||
|
||||
if let cgImage = try? imageGenerator.copyCGImage(at: CMTime(seconds: startTime, preferredTimescale: composition.duration.timescale), actualTime: nil) {
|
||||
thumbnailImage = UIImage(cgImage: cgImage)
|
||||
}
|
||||
}
|
||||
|
||||
let values = MediaEditorValues(peerId: self.context.account.peerId, originalDimensions: PixelDimensions(width: 400, height: 400), cropOffset: .zero, cropRect: CGRect(origin: .zero, size: CGSize(width: 400.0, height: 400.0)), 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
|
||||
@ -1507,8 +1521,7 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
|
||||
let thumbnailResource = LocalFileMediaResource(fileId: Int64.random(in: Int64.min ... Int64.max))
|
||||
let thumbnailSize = video.dimensions.cgSize.aspectFitted(CGSize(width: 320.0, height: 320.0))
|
||||
let thumbnailImage = scaleImageToPixelSize(image: video.thumbnail, size: thumbnailSize)
|
||||
if let thumbnailData = thumbnailImage?.jpegData(compressionQuality: 0.4) {
|
||||
if let thumbnailData = scaleImageToPixelSize(image: thumbnailImage, size: thumbnailSize)?.jpegData(compressionQuality: 0.4) {
|
||||
self.context.account.postbox.mediaBox.storeResourceData(thumbnailResource.id, data: thumbnailData)
|
||||
previewRepresentations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(thumbnailSize), resource: thumbnailResource, progressiveSizes: [], immediateThumbnailData: nil, hasVideo: false, isPersonal: false))
|
||||
}
|
||||
@ -1517,7 +1530,7 @@ public class VideoMessageCameraScreen: ViewController {
|
||||
defer {
|
||||
TempBox.shared.dispose(tempFile)
|
||||
}
|
||||
if let data = compressImageToJPEG(video.thumbnail, quality: 0.7, tempFilePath: tempFile.path) {
|
||||
if let data = compressImageToJPEG(thumbnailImage, quality: 0.7, tempFilePath: tempFile.path) {
|
||||
context.account.postbox.mediaBox.storeCachedResourceRepresentation(resource, representation: CachedVideoFirstFrameRepresentation(), data: data)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user