fix: video may in portrait mode issue
This commit is contained in:
parent
1e71f0c147
commit
81bc8eb662
|
@ -46,6 +46,7 @@ public struct AttachmentView: View {
|
|||
}()
|
||||
Spacer()
|
||||
TextField(placeholder, text: $viewModel.caption)
|
||||
.lineLimit(1)
|
||||
.textFieldStyle(.plain)
|
||||
.foregroundColor(.white)
|
||||
.placeholder(placeholder, when: viewModel.caption.isEmpty)
|
||||
|
@ -196,6 +197,7 @@ extension View {
|
|||
placeholder(when: shouldShow, alignment: alignment) {
|
||||
Text(text)
|
||||
.foregroundColor(.white.opacity(0.7))
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,15 @@ extension AttachmentViewModel {
|
|||
let exporter = NextLevelSessionExporter(withAsset: urlAsset)
|
||||
exporter.outputFileType = .mp4
|
||||
|
||||
var isLandscape: Bool = {
|
||||
guard let track = urlAsset.tracks(withMediaType: .video).first else {
|
||||
return true
|
||||
}
|
||||
|
||||
let size = track.naturalSize.applying(track.preferredTransform)
|
||||
return abs(size.width) >= abs(size.height)
|
||||
}()
|
||||
|
||||
let outputURL = try FileManager.default.createTemporaryFileURL(
|
||||
filename: UUID().uuidString,
|
||||
pathExtension: url.pathExtension
|
||||
|
@ -30,8 +39,8 @@ extension AttachmentViewModel {
|
|||
]
|
||||
exporter.videoOutputConfiguration = [
|
||||
AVVideoCodecKey: AVVideoCodecType.h264,
|
||||
AVVideoWidthKey: NSNumber(integerLiteral: 1280),
|
||||
AVVideoHeightKey: NSNumber(integerLiteral: 720),
|
||||
AVVideoWidthKey: NSNumber(integerLiteral: isLandscape ? 1280 : 720),
|
||||
AVVideoHeightKey: NSNumber(integerLiteral: isLandscape ? 720 : 1280),
|
||||
AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
|
||||
AVVideoCompressionPropertiesKey: compressionDict
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue