|
@@ -45,38 +45,49 @@ class WSSMediaOperationTool: NSObject {
|
|
|
outputPath: String,
|
|
|
progressHandle: ((Float) -> Void)? = nil,
|
|
|
finishHandle: ((OJAImageVideoDecoder.OJAImageVideoDecoderState, String?) -> Void)? = nil) {
|
|
|
- //
|
|
|
- imageVideoDecoder?.endProgressing()
|
|
|
- imageVideoDecoder?.progressChangeCallBack = nil
|
|
|
- imageVideoDecoder?.finishCombineCallBack = nil
|
|
|
- imageVideoDecoder = nil
|
|
|
- // 如果已经存在文件,先删除
|
|
|
- try? FileManager.default.removeItem(at: URL(fileURLWithPath: outputPath))
|
|
|
+ // 使用AVFoundation生成视频
|
|
|
+ if let model = images.first, let image = model.sourceImage {
|
|
|
+ let duration = model.endSeconds - model.startSeconds
|
|
|
|
|
|
- imageVideoDecoder = OJAImageVideoDecoder(imageDataArray: images, totalSeconds: duration)
|
|
|
- imageVideoDecoder?.outputPath = outputPath
|
|
|
- imageVideoDecoder?.progressChangeCallBack = { pg in
|
|
|
- progressHandle?(pg)
|
|
|
- }
|
|
|
- imageVideoDecoder?.finishCombineCallBack = { state, outputPath in
|
|
|
- finishHandle?(state, outputPath)
|
|
|
- }
|
|
|
+ WSSMediaOperationTool.makeVideo(withImage: image, duration: duration, outputPath: outputPath) { path in
|
|
|
+ finishHandle?(.finish, path)
|
|
|
+ }
|
|
|
|
|
|
- DispatchQueue.main.async { [weak self] in
|
|
|
- self?.imageVideoDecoder?.startProgressing()
|
|
|
+ progressHandle?(1.0)
|
|
|
}
|
|
|
+
|
|
|
+ // 使用GPUImage生成视频
|
|
|
+// imageVideoDecoder?.endProgressing()
|
|
|
+// imageVideoDecoder?.progressChangeCallBack = nil
|
|
|
+// imageVideoDecoder?.finishCombineCallBack = nil
|
|
|
+// imageVideoDecoder = nil
|
|
|
+// // 如果已经存在文件,先删除
|
|
|
+// try? FileManager.default.removeItem(at: URL(fileURLWithPath: outputPath))
|
|
|
+//
|
|
|
+// imageVideoDecoder = OJAImageVideoDecoder(imageDataArray: images, totalSeconds: duration)
|
|
|
+// imageVideoDecoder?.outputPath = outputPath
|
|
|
+// imageVideoDecoder?.progressChangeCallBack = { pg in
|
|
|
+// progressHandle?(pg)
|
|
|
+// }
|
|
|
+// imageVideoDecoder?.finishCombineCallBack = { state, outputPath in
|
|
|
+// finishHandle?(state, outputPath)
|
|
|
+// }
|
|
|
+//
|
|
|
+// DispatchQueue.main.async { [weak self] in
|
|
|
+// self?.imageVideoDecoder?.startProgressing()
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
func endImage2Video() {
|
|
|
- imageVideoDecoder?.endProgressing()
|
|
|
+// imageVideoDecoder?.endProgressing()
|
|
|
}
|
|
|
|
|
|
func releaseObjs() {
|
|
|
//
|
|
|
- if imageVideoDecoder != nil {
|
|
|
- imageVideoDecoder?.endProgressing()
|
|
|
- imageVideoDecoder = nil
|
|
|
- }
|
|
|
+// if imageVideoDecoder != nil {
|
|
|
+// imageVideoDecoder?.endProgressing()
|
|
|
+// imageVideoDecoder = nil
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -953,8 +964,12 @@ extension WSSMediaOperationTool {
|
|
|
/// - duration: 生成的视频时长,单位秒
|
|
|
/// - finish: 生成视频结果回调
|
|
|
class func makeVideo(withImage image: UIImage, duration: TimeInterval, outputPath: String, finish: ((String?) -> Void)?) {
|
|
|
- WSSUIImageTool.createVideo(with: image, videoDuration: duration, outputPath: outputPath) { path in
|
|
|
- finish?(path)
|
|
|
+ DispatchQueue.global(qos: .userInteractive).async {
|
|
|
+ WSSUIImageTool.createVideo(with: image, videoDuration: duration, outputPath: outputPath) { path in
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ finish?(path)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|