From 81bc8eb662c847276c8817c6d07db52268b1898d Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 14 Nov 2022 01:19:39 +0800 Subject: [PATCH] fix: video may in portrait mode issue --- .../ComposeContent/Attachment/AttachmentView.swift | 2 ++ .../Attachment/AttachmentViewModel+Compress.swift | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentView.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentView.swift index f55793591..a2567d0b6 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentView.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentView.swift @@ -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) } } } diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift index 0fd0ab085..ac1811a06 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift @@ -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 ]