Prechádzať zdrojové kódy

fix: iphone x 系列合成字幕位置不准问题

zhongbaojian 5 rokov pred
rodič
commit
662a37cfa7

+ 11 - 21
SuperShow/Tool/WSSMediaOperationTool.swift

@@ -66,7 +66,7 @@ class WSSMediaOperationTool: NSObject {
             self?.imageVideoDecoder?.startProgressing()
             self?.imageVideoDecoder?.startProgressing()
         }
         }
     }
     }
-    
+
     func endImage2Video() {
     func endImage2Video() {
         if let imagedecoder = imageVideoDecoder {
         if let imagedecoder = imageVideoDecoder {
             imageVideoDecoder?.endProgressing()
             imageVideoDecoder?.endProgressing()
@@ -119,16 +119,7 @@ extension WSSMediaOperationTool {
     /// - Parameter videoAsset: 视频资源
     /// - Parameter videoAsset: 视频资源
     /// - Returns: 视频质量
     /// - Returns: 视频质量
     class func resolvePresentName(forVideoAsset videoAsset: AVAsset) -> String {
     class func resolvePresentName(forVideoAsset videoAsset: AVAsset) -> String {
-        var presentName: String = AVAssetExportPreset960x540
-        let videoLength = videoAsset.duration.seconds
-        if videoLength < 30.0 {
-            presentName = AVAssetExportPresetHighestQuality
-        } else if videoLength >= 30.0 && videoLength < 70.0 {
-            presentName = AVAssetExportPreset1280x720
-        } else {
-            presentName = AVAssetExportPreset640x480
-        }
-        return presentName
+        return WSSCreativeTemplateConstant.getAdjustNormalPreset(videoAsset: videoAsset)
     }
     }
 
 
     /// 计算裁剪时间范围
     /// 计算裁剪时间范围
@@ -1563,16 +1554,16 @@ fileprivate extension WSSMediaOperationTool {
 
 
         var newWidth: CGFloat
         var newWidth: CGFloat
         var newHeight: CGFloat
         var newHeight: CGFloat
-        
+
         if videoRate > outputRate {
         if videoRate > outputRate {
-            //高对齐
-             newHeight = outputSize.height
-             newWidth = newHeight * videoRate
-        }else {
-             newWidth = outputSize.width
-             newHeight = newWidth / videoRate
-        }
-        
+            // 高对齐
+            newHeight = outputSize.height
+            newWidth = newHeight * videoRate
+        } else {
+            newWidth = outputSize.width
+            newHeight = newWidth / videoRate
+        }
+
         let widthScale = newWidth / videoSize.width
         let widthScale = newWidth / videoSize.width
         let heightScale = newHeight / videoSize.height
         let heightScale = newHeight / videoSize.height
 
 
@@ -1639,4 +1630,3 @@ extension WSSMediaOperationTool {
         case unkown = "未知错误"
         case unkown = "未知错误"
     }
     }
 }
 }
-

+ 8 - 2
SuperShow/UI/CoolVoice/WSSCoolVoiceSubtitleController.swift

@@ -6,6 +6,7 @@
 //  Copyright © 2019 duowan. All rights reserved.
 //  Copyright © 2019 duowan. All rights reserved.
 //
 //
 
 
+import DeviceKit
 import OJASwiftKit
 import OJASwiftKit
 import UIKit
 import UIKit
 
 
@@ -1047,7 +1048,10 @@ fileprivate extension WSSCoolVoiceSubtitleController {
             self?.movieWriter?.finishRecording(completionHandler: { [weak self] in
             self?.movieWriter?.finishRecording(completionHandler: { [weak self] in
                 let mixOutputPath: String = kOJSUserCacheDirectory + "/" + "tmp_export_mix_audio_subtitle_video" + ".mp4"
                 let mixOutputPath: String = kOJSUserCacheDirectory + "/" + "tmp_export_mix_audio_subtitle_video" + ".mp4"
                 let combineVideo = AVURLAsset(url: outputUrl)
                 let combineVideo = AVURLAsset(url: outputUrl)
-                let presentName = kOJSIsNotchiPhone ? AVAssetExportPresetHighestQuality : WSSMediaOperationTool.resolvePresentName(forVideoAsset: resultVideoAsset)
+                let presentName = WSSMediaOperationTool.resolvePresentName(forVideoAsset: resultVideoAsset)
+
+                WSSSimpleLog("🥞: \(presentName)")
+
                 self?.setupMixAudioExportDisplayLink()
                 self?.setupMixAudioExportDisplayLink()
                 self?.mixAudioExportSeesion = try? WSSMediaOperationTool.mixAudio(withAudioAsset: audioAsset,
                 self?.mixAudioExportSeesion = try? WSSMediaOperationTool.mixAudio(withAudioAsset: audioAsset,
                                                                                   forVideo: combineVideo,
                                                                                   forVideo: combineVideo,
@@ -1058,6 +1062,8 @@ fileprivate extension WSSCoolVoiceSubtitleController {
                                                                                   exportPath: mixOutputPath,
                                                                                   exportPath: mixOutputPath,
                                                                                   finish: { [weak self] mixResult in
                                                                                   finish: { [weak self] mixResult in
 
 
+                                                                                      WSSSimpleLog("#字幕合成#: \(mixOutputPath)")
+
 //                                                                                      WSSHub.dismissHub()
 //                                                                                      WSSHub.dismissHub()
                                                                                       DispatchQueue.main.async {
                                                                                       DispatchQueue.main.async {
                                                                                           hideHud()
                                                                                           hideHud()
@@ -1128,7 +1134,7 @@ fileprivate extension WSSCoolVoiceSubtitleController {
 
 
     func createTextPasterInput() {
     func createTextPasterInput() {
         let rect = AVMakeRect(aspectRatio: videoSize, insideRect: kOJSScreenBounds)
         let rect = AVMakeRect(aspectRatio: videoSize, insideRect: kOJSScreenBounds)
-        let placeholer: UIView = UIView(frame: rect)
+        let placeholer: UIView = UIView(frame: CGRect(origin: CGPoint.zero, size: rect.size))
 
 
         /// 初始化文字Text
         /// 初始化文字Text
         textPasterInfoData.removeAll()
         textPasterInfoData.removeAll()