mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Various fixes
This commit is contained in:
parent
b1aa62e9cc
commit
0fdb24253f
1 changed files with 5 additions and 41 deletions
|
|
@ -423,11 +423,7 @@ public final class MediaEditorVideoExport {
|
|||
duration = CMTime(seconds: 5.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
|
||||
}
|
||||
}
|
||||
if self.configuration.values.videoBounce, case .video = self.subject {
|
||||
self.durationValue = CMTimeAdd(duration, duration)
|
||||
} else {
|
||||
self.durationValue = duration
|
||||
}
|
||||
self.durationValue = duration
|
||||
|
||||
let _ = (combineLatest(signals)
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] additionalInputs in
|
||||
|
|
@ -516,49 +512,17 @@ public final class MediaEditorVideoExport {
|
|||
self.mainVideoScale = scale
|
||||
self.mainVideoOffset = offset
|
||||
self.textureRotation = rotation
|
||||
var mainTimeRange = CMTimeRange(start: .zero, duration: asset.duration)
|
||||
if let timeRange = self.configuration.timeRange {
|
||||
mainTimeRange = timeRange
|
||||
} else if isStory && asset.duration.seconds > 60.0 {
|
||||
mainTimeRange = CMTimeRange(start: .zero, duration: CMTime(seconds: 60.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC)))
|
||||
}
|
||||
if let videoAssetTrack = asset.tracks(withMediaType: .video).first {
|
||||
if let compositionTrack = composition?.addMutableTrack(withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid) {
|
||||
mainVideoTrack = compositionTrack
|
||||
compositionTrack.preferredTransform = videoAssetTrack.preferredTransform
|
||||
|
||||
try? compositionTrack.insertTimeRange(mainTimeRange, of: videoAssetTrack, at: .zero)
|
||||
|
||||
if self.configuration.values.videoBounce {
|
||||
let sourceFrameRate: Float
|
||||
if videoAssetTrack.nominalFrameRate > 0.0 {
|
||||
sourceFrameRate = videoAssetTrack.nominalFrameRate
|
||||
} else if self.configuration.frameRate > 0.0 {
|
||||
sourceFrameRate = self.configuration.frameRate
|
||||
} else {
|
||||
sourceFrameRate = 30.0
|
||||
}
|
||||
let roundedFrameRate = max(1, Int(round(sourceFrameRate)))
|
||||
let frameDuration = CMTime(value: 1, timescale: Int32(roundedFrameRate))
|
||||
|
||||
var insertionTime = mainTimeRange.duration
|
||||
var cursor = CMTimeSubtract(CMTimeRangeGetEnd(mainTimeRange), frameDuration)
|
||||
while CMTimeCompare(cursor, mainTimeRange.start) >= 0 {
|
||||
let remaining = CMTimeSubtract(CMTimeRangeGetEnd(mainTimeRange), cursor)
|
||||
let segmentDuration = CMTimeCompare(frameDuration, remaining) <= 0 ? frameDuration : remaining
|
||||
if segmentDuration.seconds > 0.0 {
|
||||
let segmentRange = CMTimeRange(start: cursor, duration: segmentDuration)
|
||||
try? compositionTrack.insertTimeRange(segmentRange, of: videoAssetTrack, at: insertionTime)
|
||||
insertionTime = CMTimeAdd(insertionTime, segmentDuration)
|
||||
}
|
||||
cursor = CMTimeSubtract(cursor, frameDuration)
|
||||
}
|
||||
}
|
||||
|
||||
try? compositionTrack.insertTimeRange(CMTimeRange(start: .zero, duration: asset.duration), of: videoAssetTrack, at: .zero)
|
||||
}
|
||||
}
|
||||
if let audioAssetTrack = asset.tracks(withMediaType: .audio).first, !self.configuration.values.videoIsMuted {
|
||||
if let compositionTrack = composition?.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid) {
|
||||
try? compositionTrack.insertTimeRange(mainTimeRange, of: audioAssetTrack, at: .zero)
|
||||
try? compositionTrack.insertTimeRange(CMTimeRange(start: .zero, duration: asset.duration), of: audioAssetTrack, at: .zero)
|
||||
|
||||
if let volume = self.configuration.values.videoVolume, volume != 1.0 {
|
||||
let trackParameters = AVMutableAudioMixInputParameters(track: compositionTrack)
|
||||
|
|
@ -568,7 +532,7 @@ public final class MediaEditorVideoExport {
|
|||
}
|
||||
}
|
||||
}
|
||||
if !self.configuration.values.videoBounce, let timeRange = self.configuration.timeRange {
|
||||
if let timeRange = self.configuration.timeRange {
|
||||
readerRange = timeRange
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue