mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various fixes
This commit is contained in:
parent
25ddb78040
commit
4bf1e830c8
@ -470,8 +470,6 @@ class ChatTimerScreenNode: ViewControllerTracingNode, UIScrollViewDelegate, UIPi
|
||||
|
||||
self.contentContainerNode.view.addSubview(pickerView)
|
||||
self.pickerView = pickerView
|
||||
|
||||
pickerView.selectRow(1, inComponent: 0, animated: false)
|
||||
case .autoremove:
|
||||
let pickerView = TimerCustomPickerView()
|
||||
pickerView.dataSource = self
|
||||
|
@ -1087,10 +1087,10 @@ public extension MediaEditorValues {
|
||||
}
|
||||
|
||||
var requiresComposing: Bool {
|
||||
if self.originalDimensions.width > 0 && abs((Double(self.originalDimensions.height) / Double(self.originalDimensions.width)) - 1.7777778) > 0.001 {
|
||||
if abs(1.0 - self.cropScale) > 0.0 {
|
||||
return true
|
||||
}
|
||||
if abs(1.0 - self.cropScale) > 0.0 {
|
||||
if self.cropRect != nil {
|
||||
return true
|
||||
}
|
||||
if self.cropOffset != .zero {
|
||||
|
@ -15,7 +15,7 @@ enum ExportWriterStatus {
|
||||
|
||||
protocol MediaEditorVideoExportWriter {
|
||||
func setup(configuration: MediaEditorVideoExport.Configuration, outputPath: String)
|
||||
func setupVideoInput(configuration: MediaEditorVideoExport.Configuration, sourceFrameRate: Float)
|
||||
func setupVideoInput(configuration: MediaEditorVideoExport.Configuration, preferredTransform: CGAffineTransform?, sourceFrameRate: Float)
|
||||
func setupAudioInput(configuration: MediaEditorVideoExport.Configuration)
|
||||
|
||||
func startWriting() -> Bool
|
||||
@ -62,25 +62,38 @@ public final class MediaEditorVideoAVAssetWriter: MediaEditorVideoExportWriter {
|
||||
Logger.shared.log("VideoExport", "Did setup asset writer")
|
||||
}
|
||||
|
||||
func setupVideoInput(configuration: MediaEditorVideoExport.Configuration, sourceFrameRate: Float) {
|
||||
func setupVideoInput(configuration: MediaEditorVideoExport.Configuration, preferredTransform: CGAffineTransform?, sourceFrameRate: Float) {
|
||||
guard let writer = self.writer else {
|
||||
return
|
||||
}
|
||||
|
||||
Logger.shared.log("VideoExport", "Will setup video input")
|
||||
|
||||
var dimensions = configuration.dimensions
|
||||
var videoSettings = configuration.videoSettings
|
||||
if var compressionSettings = videoSettings[AVVideoCompressionPropertiesKey] as? [String: Any] {
|
||||
compressionSettings[AVVideoExpectedSourceFrameRateKey] = sourceFrameRate
|
||||
videoSettings[AVVideoCompressionPropertiesKey] = compressionSettings
|
||||
}
|
||||
if let preferredTransform {
|
||||
if (preferredTransform.b == -1 && preferredTransform.c == 1) || (preferredTransform.b == 1 && preferredTransform.c == -1) {
|
||||
dimensions = CGSize(width: dimensions.height, height: dimensions.width)
|
||||
}
|
||||
videoSettings[AVVideoWidthKey] = Int(dimensions.width)
|
||||
videoSettings[AVVideoHeightKey] = Int(dimensions.height)
|
||||
}
|
||||
|
||||
let videoInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoSettings)
|
||||
if let preferredTransform {
|
||||
videoInput.transform = preferredTransform
|
||||
|
||||
}
|
||||
videoInput.expectsMediaDataInRealTime = false
|
||||
|
||||
let sourcePixelBufferAttributes = [
|
||||
kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA,
|
||||
kCVPixelBufferWidthKey as String: UInt32(configuration.dimensions.width),
|
||||
kCVPixelBufferHeightKey as String: UInt32(configuration.dimensions.height)
|
||||
kCVPixelBufferWidthKey as String: UInt32(dimensions.width),
|
||||
kCVPixelBufferHeightKey as String: UInt32(dimensions.height)
|
||||
]
|
||||
self.adaptor = AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: videoInput, sourcePixelBufferAttributes: sourcePixelBufferAttributes)
|
||||
|
||||
@ -483,7 +496,15 @@ public final class MediaEditorVideoExport {
|
||||
kCVPixelBufferMetalCompatibilityKey as String: true,
|
||||
AVVideoColorPropertiesKey: colorProperties
|
||||
]
|
||||
if let videoTrack = videoTracks.first, videoTrack.preferredTransform.isIdentity && !self.configuration.values.requiresComposing {
|
||||
|
||||
let originalDimensions = self.configuration.values.originalDimensions
|
||||
var isNotFullscreen = false
|
||||
if case .video(_, true) = self.subject, originalDimensions.width > 0 && abs((Double(originalDimensions.height) / Double(originalDimensions.width)) - 1.7777778) > 0.001 {
|
||||
isNotFullscreen = true
|
||||
}
|
||||
var preferredTransform: CGAffineTransform?
|
||||
if let videoTrack = videoTracks.first, !self.configuration.values.requiresComposing && !isNotFullscreen {
|
||||
preferredTransform = videoTrack.preferredTransform
|
||||
} else {
|
||||
self.setupComposer()
|
||||
}
|
||||
@ -517,7 +538,7 @@ public final class MediaEditorVideoExport {
|
||||
} else {
|
||||
sourceFrameRate = 30.0
|
||||
}
|
||||
writer.setupVideoInput(configuration: self.configuration, sourceFrameRate: sourceFrameRate)
|
||||
writer.setupVideoInput(configuration: self.configuration, preferredTransform: preferredTransform, sourceFrameRate: sourceFrameRate)
|
||||
} else {
|
||||
self.videoOutput = nil
|
||||
}
|
||||
@ -558,7 +579,7 @@ public final class MediaEditorVideoExport {
|
||||
return
|
||||
}
|
||||
writer.setup(configuration: self.configuration, outputPath: self.outputPath)
|
||||
writer.setupVideoInput(configuration: self.configuration, sourceFrameRate: 30.0)
|
||||
writer.setupVideoInput(configuration: self.configuration, preferredTransform: nil, sourceFrameRate: 30.0)
|
||||
|
||||
if let audioData = self.configuration.values.audioTrack {
|
||||
let mixComposition = AVMutableComposition()
|
||||
|
@ -510,7 +510,7 @@ public func fetchLocalFileVideoMediaResource(postbox: Postbox, resource: LocalFi
|
||||
} else {
|
||||
if alwaysUseModernPipeline && !isImage, let track = avAsset.tracks(withMediaType: .video).first {
|
||||
let dimensions = track.naturalSize.applying(track.preferredTransform)
|
||||
mediaEditorValues = MediaEditorValues(dimensions: PixelDimensions(dimensions), qualityPreset: qualityPreset)
|
||||
mediaEditorValues = MediaEditorValues(dimensions: PixelDimensions(width: Int32(abs(dimensions.width)), height: Int32(abs(dimensions.height))), qualityPreset: qualityPreset)
|
||||
}
|
||||
}
|
||||
let tempFile = EngineTempBox.shared.tempFile(fileName: "video.mp4")
|
||||
|
Loading…
x
Reference in New Issue
Block a user