mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix image video export
This commit is contained in:
parent
697fcf63df
commit
03e64b2f74
@ -554,14 +554,16 @@ public final class MediaEditorVideoExport {
|
||||
}
|
||||
}
|
||||
|
||||
private var imageArguments: (duration: Double, frameRate: Double, position: CMTime)?
|
||||
|
||||
private func encodeImageVideo() -> Bool {
|
||||
guard let writer = self.writer, let composer = self.composer, case let .image(image) = self.subject else {
|
||||
guard let writer = self.writer, let composer = self.composer, case let .image(image) = self.subject, let imageArguments = self.imageArguments else {
|
||||
return false
|
||||
}
|
||||
|
||||
let duration: Double = 5.0
|
||||
let frameRate: Double = Double(self.configuration.frameRate)
|
||||
var position: CMTime = CMTime(value: 0, timescale: Int32(frameRate))
|
||||
let duration = imageArguments.duration
|
||||
let frameRate = imageArguments.frameRate
|
||||
var position = imageArguments.position
|
||||
|
||||
var appendFailed = false
|
||||
while writer.isReadyForMoreVideoData {
|
||||
@ -580,15 +582,10 @@ public final class MediaEditorVideoExport {
|
||||
composer.processImage(inputImage: image, pool: writer.pixelBufferPool, time: position, completion: { pixelBuffer in
|
||||
if let pixelBuffer {
|
||||
if !writer.appendPixelBuffer(pixelBuffer, at: position) {
|
||||
Logger.shared.log("VideoExport", "Failed to append pixelbuffer at \(position.seconds), trying to wait")
|
||||
Queue.concurrentDefaultQueue().after(1.0, {
|
||||
if !writer.appendPixelBuffer(pixelBuffer, at: position) {
|
||||
Logger.shared.log("VideoExport", "Failed to append pixelbuffer at \(position.seconds), complete failure")
|
||||
Logger.shared.log("VideoExport", "Failed to append pixelbuffer at \(position.seconds), stopping")
|
||||
writer.markVideoAsFinished()
|
||||
appendFailed = true
|
||||
self.semaphore.signal()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Logger.shared.log("VideoExport", "Appended pixelbuffer at \(position.seconds)")
|
||||
|
||||
@ -611,6 +608,9 @@ public final class MediaEditorVideoExport {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
self.imageArguments = (duration, frameRate, position)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -751,6 +751,8 @@ public final class MediaEditorVideoExport {
|
||||
|
||||
writer.startSession(atSourceTime: .zero)
|
||||
|
||||
self.imageArguments = (5.0, Double(self.configuration.frameRate), CMTime(value: 0, timescale: Int32(self.configuration.frameRate)))
|
||||
|
||||
var exportForVideoOutput: MediaEditorVideoExport? = self
|
||||
writer.requestVideoDataWhenReady(on: self.queue.queue) {
|
||||
guard let export = exportForVideoOutput else { return }
|
||||
|
Loading…
x
Reference in New Issue
Block a user