|
@@ -56,16 +56,16 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
tempVideoOptions.isNetworkAccessAllowed = true
|
|
|
tempVideoOptions.deliveryMode = .highQualityFormat
|
|
|
tempVideoOptions.progressHandler = { progress, error, pointer, info in
|
|
|
- PQLog(message: "导出playerItem-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
+ BFLog(message: "导出playerItem-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
}
|
|
|
PHImageManager().requestPlayerItem(forVideo: phAsset, options: tempVideoOptions) { (playerItem, info) in
|
|
|
let size = try! (playerItem?.asset as? AVURLAsset)?.url.resourceValues(forKeys: [.fileSizeKey])
|
|
|
- PQLog(message: "size = \(String(describing: size))")
|
|
|
+ BFLog(message: "size = \(String(describing: size))")
|
|
|
resultHandler(playerItem, Float64(size?.fileSize ?? 0), info)
|
|
|
}
|
|
|
}else{
|
|
|
let size = try! (playerItem?.asset as? AVURLAsset)?.url.resourceValues(forKeys: [.fileSizeKey])
|
|
|
- PQLog(message: "size = \(String(describing: size))")
|
|
|
+ BFLog(message: "size = \(String(describing: size))")
|
|
|
resultHandler(playerItem, Float64(size?.fileSize ?? 0), info)
|
|
|
}
|
|
|
}
|
|
@@ -85,17 +85,17 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
tempVideoOptions.isNetworkAccessAllowed = true
|
|
|
tempVideoOptions.deliveryMode = .highQualityFormat
|
|
|
tempVideoOptions.progressHandler = { progress, error, pointer, info in
|
|
|
- PQLog(message: "导出playerItem-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
+ BFLog(message: "导出playerItem-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
}
|
|
|
PHImageManager.default().requestAVAsset(forVideo: phAsset, options: tempVideoOptions) { tempAvAsset, tempAudioMix, tempInfo in
|
|
|
let size = try! (tempAvAsset as? AVURLAsset)?.url.resourceValues(forKeys: [.fileSizeKey])
|
|
|
- PQLog(message: "size = \(String(describing: size))")
|
|
|
+ BFLog(message: "size = \(String(describing: size))")
|
|
|
resultHandler(tempAvAsset, size?.fileSize ?? 0, tempAudioMix, tempInfo)
|
|
|
}
|
|
|
}else{
|
|
|
let size = try! (avAsset as? AVURLAsset)?.url.resourceValues(forKeys: [.fileSizeKey])
|
|
|
resultHandler(avAsset, size?.fileSize ?? 0, audioMix, info)
|
|
|
- PQLog(message: "size = \(String(describing: size))")
|
|
|
+ BFLog(message: "size = \(String(describing: size))")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -107,7 +107,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
/// - resultHandler: <#resultHandler description#>
|
|
|
/// - Returns: <#description#>
|
|
|
class func exportPHAssetToMP4(phAsset: PHAsset, isAdjustRotationAngle: Bool = true, isCancelCurrentExport: Bool = false,deliveryMode: PHVideoRequestOptionsDeliveryMode? = .automatic, resultHandler: @escaping (_ phAsset: PHAsset, _ aVAsset: AVAsset?, _ filePath: String?, _ errorMsg: String?) -> Void) {
|
|
|
- PQLog(message: "导出相册视频-开始导出:phAsset = \(phAsset)")
|
|
|
+ BFLog(message: "导出相册视频-开始导出:phAsset = \(phAsset)")
|
|
|
if isCancelCurrentExport {
|
|
|
currentExportSession?.cancelExport()
|
|
|
}
|
|
@@ -119,23 +119,23 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
let filePath = photoLibraryDirectory + (fileName.kf.md5).kf.md5 + ".mp4"
|
|
|
let data = try? Data(contentsOf: NSURL.fileURL(withPath: filePath))
|
|
|
if FileManager.default.fileExists(atPath: filePath) && (data?.count ?? 0) > fileSize / 40 {
|
|
|
- PQLog(message: "导出相册视频-已经导出完成:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频-已经导出完成:\(filePath)")
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(phAsset, avAsset, filePath, nil)
|
|
|
}
|
|
|
} else {
|
|
|
let tempExportSession = PQSingletoMemoryUtil.shared.allExportSession[phAsset]
|
|
|
if tempExportSession != nil {
|
|
|
- PQLog(message: "导出相册视频-正在导出")
|
|
|
+ BFLog(message: "导出相册视频-正在导出")
|
|
|
return
|
|
|
}
|
|
|
- PQLog(message: "导出相册视频-未导出视频过,开始导出:phAsset = \(phAsset)")
|
|
|
+ BFLog(message: "导出相册视频-未导出视频过,开始导出:phAsset = \(phAsset)")
|
|
|
// 删除以创建地址
|
|
|
if FileManager.default.fileExists(atPath: filePath) {
|
|
|
do {
|
|
|
try FileManager.default.removeItem(at: NSURL.fileURL(withPath: filePath))
|
|
|
} catch {
|
|
|
- PQLog(message: "导出相册视频-error == \(error)")
|
|
|
+ BFLog(message: "导出相册视频-error == \(error)")
|
|
|
}
|
|
|
}
|
|
|
let requestOptions = PHVideoRequestOptions()
|
|
@@ -145,11 +145,11 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
// 下载iCloud视频
|
|
|
requestOptions.isNetworkAccessAllowed = false
|
|
|
requestOptions.progressHandler = { progress, error, pointer, info in
|
|
|
- PQLog(message: "导出相册视频-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
+ BFLog(message: "导出相册视频-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
}
|
|
|
requestOptions.deliveryMode = deliveryMode ?? .automatic
|
|
|
PHImageManager.default().requestExportSession(forVideo: phAsset, options: requestOptions, exportPreset: (deliveryMode == .automatic || deliveryMode == .mediumQualityFormat) ? AVAssetExportPresetMediumQuality :(deliveryMode == .highQualityFormat ? AVAssetExportPresetHighestQuality : AVAssetExportPresetLowQuality) , resultHandler: { avAssetExportSession, _ in
|
|
|
- PQLog(message: "导出相册视频-请求到导出 avAssetExportSession = \(String(describing: avAssetExportSession))")
|
|
|
+ BFLog(message: "导出相册视频-请求到导出 avAssetExportSession = \(String(describing: avAssetExportSession))")
|
|
|
currentExportSession = avAssetExportSession
|
|
|
if avAssetExportSession != nil {
|
|
|
PQSingletoMemoryUtil.shared.allExportSession[phAsset] = avAssetExportSession!
|
|
@@ -193,11 +193,11 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
videoComposition.instructions = [roateInstruction]
|
|
|
avAssetExportSession?.videoComposition = videoComposition
|
|
|
} else {
|
|
|
- PQLog(message: "firstTrack is error !!!")
|
|
|
+ BFLog(message: "firstTrack is error !!!")
|
|
|
}
|
|
|
}
|
|
|
avAssetExportSession?.exportAsynchronously(completionHandler: {
|
|
|
- PQLog(message: "导出相册视频-progress = \(avAssetExportSession?.progress ?? 0),status = \(String(describing: avAssetExportSession?.status))")
|
|
|
+ BFLog(message: "导出相册视频-progress = \(avAssetExportSession?.progress ?? 0),status = \(String(describing: avAssetExportSession?.status))")
|
|
|
switch avAssetExportSession?.status {
|
|
|
case .unknown:
|
|
|
DispatchQueue.main.async {
|
|
@@ -205,32 +205,32 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
}
|
|
|
avAssetExportSession?.cancelExport()
|
|
|
PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
- PQLog(message: "导出相册视频-发生未知错误:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "导出相册视频-发生未知错误:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
case .waiting:
|
|
|
- PQLog(message: "导出相册视频-等待导出mp4:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频-等待导出mp4:\(filePath)")
|
|
|
case .exporting:
|
|
|
- PQLog(message: "导出相册视频-导出相册视频中...:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频-导出相册视频中...:\(filePath)")
|
|
|
case .completed:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(phAsset, avAsset, filePath, nil)
|
|
|
}
|
|
|
avAssetExportSession?.cancelExport()
|
|
|
PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
- PQLog(message: "导出相册视频-导出完成:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频-导出完成:\(filePath)")
|
|
|
case .failed:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(phAsset, avAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
}
|
|
|
avAssetExportSession?.cancelExport()
|
|
|
PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
- PQLog(message: "导出相册视频-导出失败:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "导出相册视频-导出失败:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
case .cancelled:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(phAsset, avAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
}
|
|
|
avAssetExportSession?.cancelExport()
|
|
|
PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
- PQLog(message: "导出相册视频-取消导出:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "导出相册视频-取消导出:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
default:
|
|
|
break
|
|
|
}
|
|
@@ -238,7 +238,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
})
|
|
|
}
|
|
|
} else if avAsset is AVComposition {
|
|
|
- PQLog(message: "导出相册视频-是AVComposition = \(String(describing: avAsset))")
|
|
|
+ BFLog(message: "导出相册视频-是AVComposition = \(String(describing: avAsset))")
|
|
|
let assetResources = PHAssetResource.assetResources(for: phAsset)
|
|
|
var resource: PHAssetResource?
|
|
|
for assetRes in assetResources {
|
|
@@ -280,7 +280,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
/// - resultHandler: <#resultHandler description#>
|
|
|
/// - Returns: <#description#>
|
|
|
class func writePHAssetDataToMP4(phAsset: PHAsset, isAdjustRotationAngle: Bool = true, isCancelCurrentExport: Bool = false,deliveryMode: PHVideoRequestOptionsDeliveryMode? = .automatic, resultHandler: @escaping (_ phAsset: PHAsset, _ aVAsset: AVAsset?, _ filePath: String?, _ errorMsg: String?) -> Void) {
|
|
|
- PQLog(message: "导出相册视频-开始导出:phAsset = \(phAsset)")
|
|
|
+ BFLog(message: "导出相册视频-开始导出:phAsset = \(phAsset)")
|
|
|
if isCancelCurrentExport {
|
|
|
currentExportSession?.cancelExport()
|
|
|
}
|
|
@@ -292,29 +292,29 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
let filePath = photoLibraryDirectory + fileName.kf.md5 + ".mp4"
|
|
|
let data = try? Data(contentsOf: NSURL.fileURL(withPath: filePath))
|
|
|
if FileManager.default.fileExists(atPath: filePath) && (data?.count ?? 0) > fileSize / 40 {
|
|
|
- PQLog(message: "导出相册视频-已经导出完成:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频-已经导出完成:\(filePath)")
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(phAsset, avAsset, filePath, nil)
|
|
|
}
|
|
|
} else {
|
|
|
let tempExportSession = PQSingletoMemoryUtil.shared.allExportSession[phAsset]
|
|
|
if tempExportSession != nil {
|
|
|
- PQLog(message: "导出相册视频-正在导出")
|
|
|
+ BFLog(message: "导出相册视频-正在导出")
|
|
|
return
|
|
|
}
|
|
|
- PQLog(message: "导出相册视频-未导出视频过,开始导出:phAsset = \(phAsset)")
|
|
|
+ BFLog(message: "导出相册视频-未导出视频过,开始导出:phAsset = \(phAsset)")
|
|
|
// 删除以创建地址
|
|
|
if FileManager.default.fileExists(atPath: filePath) {
|
|
|
do {
|
|
|
try FileManager.default.removeItem(at: NSURL.fileURL(withPath: filePath))
|
|
|
} catch {
|
|
|
- PQLog(message: "导出相册视频-error == \(error)")
|
|
|
+ BFLog(message: "导出相册视频-error == \(error)")
|
|
|
}
|
|
|
}
|
|
|
do {
|
|
|
try FileManager.default.copyItem(at: (avAsset as! AVURLAsset).url, to: URL.init(fileURLWithPath: filePath))
|
|
|
} catch {
|
|
|
- PQLog(message: "导出相册视频-error == \(error)")
|
|
|
+ BFLog(message: "导出相册视频-error == \(error)")
|
|
|
}
|
|
|
|
|
|
// NSError *error;
|
|
@@ -342,12 +342,12 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
// // 下载iCloud视频
|
|
|
// requestOptions.isNetworkAccessAllowed = false
|
|
|
// requestOptions.progressHandler = { progress, error, pointer, info in
|
|
|
-// PQLog(message: "导出相册视频-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
+// BFLog(message: "导出相册视频-progress = \(progress),error = \(String(describing: error)),pointer = \(pointer),info = \(String(describing: info))")
|
|
|
// }
|
|
|
// requestOptions.deliveryMode = deliveryMode ?? .automatic
|
|
|
|
|
|
// PHImageManager.default().requestExportSession(forVideo: phAsset, options: requestOptions, exportPreset: (deliveryMode == .automatic || deliveryMode == .mediumQualityFormat) ? AVAssetExportPreset1920x1080 :(deliveryMode == .highQualityFormat ? AVAssetExportPresetHighestQuality : AVAssetExportPresetLowQuality) , resultHandler: { avAssetExportSession, _ in
|
|
|
-// PQLog(message: "导出相册视频-请求到导出 avAssetExportSession = \(avAssetExportSession)")
|
|
|
+// BFLog(message: "导出相册视频-请求到导出 avAssetExportSession = \(avAssetExportSession)")
|
|
|
// currentExportSession = avAssetExportSession
|
|
|
// if avAssetExportSession != nil {
|
|
|
// PQSingletoMemoryUtil.shared.allExportSession[phAsset] = avAssetExportSession!
|
|
@@ -391,12 +391,12 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
// videoComposition.instructions = [roateInstruction]
|
|
|
// avAssetExportSession?.videoComposition = videoComposition
|
|
|
// } else {
|
|
|
-// PQLog(message: "firstTrack is error !!!")
|
|
|
+// BFLog(message: "firstTrack is error !!!")
|
|
|
// }
|
|
|
// }
|
|
|
// avAssetExportSession?.shouldOptimizeForNetworkUse = true
|
|
|
// avAssetExportSession?.exportAsynchronously(completionHandler: {
|
|
|
-// PQLog(message: "导出相册视频-progress = \(avAssetExportSession?.progress ?? 0),status = \(String(describing: avAssetExportSession?.status))")
|
|
|
+// BFLog(message: "导出相册视频-progress = \(avAssetExportSession?.progress ?? 0),status = \(String(describing: avAssetExportSession?.status))")
|
|
|
// switch avAssetExportSession?.status {
|
|
|
// case .unknown:
|
|
|
// DispatchQueue.main.async {
|
|
@@ -404,32 +404,32 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
// }
|
|
|
// avAssetExportSession?.cancelExport()
|
|
|
// PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
-// PQLog(message: "导出相册视频-发生未知错误:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+// BFLog(message: "导出相册视频-发生未知错误:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
// case .waiting:
|
|
|
-// PQLog(message: "导出相册视频-等待导出mp4:\(filePath)")
|
|
|
+// BFLog(message: "导出相册视频-等待导出mp4:\(filePath)")
|
|
|
// case .exporting:
|
|
|
-// PQLog(message: "导出相册视频-导出相册视频中...:\(filePath)")
|
|
|
+// BFLog(message: "导出相册视频-导出相册视频中...:\(filePath)")
|
|
|
// case .completed:
|
|
|
// DispatchQueue.main.async {
|
|
|
// resultHandler(phAsset, avAsset, filePath, nil)
|
|
|
// }
|
|
|
// avAssetExportSession?.cancelExport()
|
|
|
// PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
-// PQLog(message: "导出相册视频-导出完成:\(filePath)")
|
|
|
+// BFLog(message: "导出相册视频-导出完成:\(filePath)")
|
|
|
// case .failed:
|
|
|
// DispatchQueue.main.async {
|
|
|
// resultHandler(phAsset, avAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
// }
|
|
|
// avAssetExportSession?.cancelExport()
|
|
|
// PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
-// PQLog(message: "导出相册视频-导出失败:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+// BFLog(message: "导出相册视频-导出失败:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
// case .cancelled:
|
|
|
// DispatchQueue.main.async {
|
|
|
// resultHandler(phAsset, avAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
// }
|
|
|
// avAssetExportSession?.cancelExport()
|
|
|
// PQSingletoMemoryUtil.shared.allExportSession.removeValue(forKey: phAsset)
|
|
|
-// PQLog(message: "导出相册视频-取消导出:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+// BFLog(message: "导出相册视频-取消导出:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
// default:
|
|
|
// break
|
|
|
// }
|
|
@@ -437,7 +437,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
// })
|
|
|
}
|
|
|
} else if avAsset is AVComposition {
|
|
|
- PQLog(message: "导出相册视频-是AVComposition = \(String(describing: avAsset))")
|
|
|
+ BFLog(message: "导出相册视频-是AVComposition = \(String(describing: avAsset))")
|
|
|
let assetResources = PHAssetResource.assetResources(for: phAsset)
|
|
|
var resource: PHAssetResource?
|
|
|
for assetRes in assetResources {
|
|
@@ -479,7 +479,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
/// - resultHandler: <#resultHandler description#>
|
|
|
class func exportAVAssetToMP4(aVAsset: AVURLAsset, isAdjustRotationAngle: Bool = true, resultHandler: @escaping (_ aVAsset: AVURLAsset?, _ filePath: String?, _ errorMsg: String?) -> Void) {
|
|
|
currentExportSession?.cancelExport()
|
|
|
- PQLog(message: "开始导出相册视频:url = \(aVAsset.url.absoluteString)")
|
|
|
+ BFLog(message: "开始导出相册视频:url = \(aVAsset.url.absoluteString)")
|
|
|
// 创建目录
|
|
|
createDirectory(path: photoLibraryDirectory)
|
|
|
let fileName = aVAsset.url.absoluteString
|
|
@@ -491,7 +491,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
resultHandler(aVAsset, filePath, nil)
|
|
|
}
|
|
|
} else {
|
|
|
- PQLog(message: "未导出视频过,开始导出:aVAsset = \(aVAsset)")
|
|
|
+ BFLog(message: "未导出视频过,开始导出:aVAsset = \(aVAsset)")
|
|
|
// 删除以创建地址
|
|
|
try? FileManager.default.removeItem(at: NSURL.fileURL(withPath: filePath))
|
|
|
let avAssetExportSession = AVAssetExportSession(asset: aVAsset, presetName: AVAssetExportPreset1280x720)
|
|
@@ -536,32 +536,32 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
|
|
|
avAssetExportSession?.shouldOptimizeForNetworkUse = true
|
|
|
avAssetExportSession?.exportAsynchronously(completionHandler: {
|
|
|
- PQLog(message: "导出相册视频progress = \(avAssetExportSession?.progress ?? 0)")
|
|
|
+ BFLog(message: "导出相册视频progress = \(avAssetExportSession?.progress ?? 0)")
|
|
|
switch avAssetExportSession?.status {
|
|
|
case .unknown:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(aVAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
}
|
|
|
- PQLog(message: "导出相册视频发生未知错误:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "导出相册视频发生未知错误:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
case .waiting:
|
|
|
- PQLog(message: "等待导出mp4:\(filePath)")
|
|
|
+ BFLog(message: "等待导出mp4:\(filePath)")
|
|
|
case .exporting:
|
|
|
- PQLog(message: "导出相册视频中...:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频中...:\(filePath)")
|
|
|
case .completed:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(aVAsset, filePath, nil)
|
|
|
}
|
|
|
- PQLog(message: "导出相册视频完成:\(filePath)")
|
|
|
+ BFLog(message: "导出相册视频完成:\(filePath)")
|
|
|
case .failed:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(aVAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
}
|
|
|
- PQLog(message: "导出相册视频失败:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "导出相册视频失败:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
case .cancelled:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(aVAsset, nil, avAssetExportSession?.error?.localizedDescription)
|
|
|
}
|
|
|
- PQLog(message: "取消导出相册视频:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "取消导出相册视频:\(filePath),\(avAssetExportSession?.error?.localizedDescription ?? "")")
|
|
|
default:
|
|
|
break
|
|
|
}
|
|
@@ -624,26 +624,26 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
exportSession?.exportAsynchronously(completionHandler: {
|
|
|
switch exportSession?.status {
|
|
|
case .waiting:
|
|
|
- PQLog(message: "等待导出mp3:\(filePath)")
|
|
|
+ BFLog(message: "等待导出mp3:\(filePath)")
|
|
|
case .exporting:
|
|
|
- PQLog(message: "导出中...:\(filePath)")
|
|
|
+ BFLog(message: "导出中...:\(filePath)")
|
|
|
case .completed:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(url, filePath, startTime, endTime, nil)
|
|
|
}
|
|
|
- PQLog(message: "导出完成:\(filePath)")
|
|
|
+ BFLog(message: "导出完成:\(filePath)")
|
|
|
|
|
|
case .cancelled, .failed, .unknown:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(url, nil, startTime, endTime, exportSession?.error?.localizedDescription)
|
|
|
}
|
|
|
- PQLog(message: "导出失败:\(filePath),\(exportSession?.error?.localizedDescription ?? "")")
|
|
|
+ BFLog(message: "导出失败:\(filePath),\(exportSession?.error?.localizedDescription ?? "")")
|
|
|
default:
|
|
|
break
|
|
|
}
|
|
|
})
|
|
|
case .loading:
|
|
|
- PQLog(message: "加载中...:\(url)")
|
|
|
+ BFLog(message: "加载中...:\(url)")
|
|
|
case .failed, .cancelled, .unknown:
|
|
|
DispatchQueue.main.async {
|
|
|
resultHandler(url, nil, startTime, endTime, "导出失败")
|
|
@@ -663,11 +663,11 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
class func createLocalFile(sourceFilePath: String, completeHandle: (_ isFileExists: Bool, _ isCreateSuccess: Bool, _ filePath: String) -> Void) {
|
|
|
let cLocalPath = NSString(string: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!).appendingPathComponent("\(sourceFilePath.kf.md5).mp4")
|
|
|
if FileManager.default.fileExists(atPath: cLocalPath) {
|
|
|
- PQLog(message: "文件已经存在:\(cLocalPath)")
|
|
|
+ BFLog(message: "文件已经存在:\(cLocalPath)")
|
|
|
completeHandle(true, false, cLocalPath)
|
|
|
} else {
|
|
|
let result = FileManager.default.createFile(atPath: cLocalPath, contents: nil, attributes: nil)
|
|
|
- PQLog(message: "文件创建:\(cLocalPath),\(result)")
|
|
|
+ BFLog(message: "文件创建:\(cLocalPath),\(result)")
|
|
|
completeHandle(false, result, cLocalPath)
|
|
|
}
|
|
|
}
|
|
@@ -680,7 +680,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
/// - Returns: <#description#>
|
|
|
class func requestAssetImage(asset: PHAsset, itemSize: CGSize, resultHandler: @escaping (UIImage?, [AnyHashable: Any]?) -> Void) {
|
|
|
PHCachingImageManager().requestImage(for: asset, targetSize: itemSize, contentMode: .aspectFill, options: imagesOptions, resultHandler: { image, info in
|
|
|
- PQLog(message: "info = \(info ?? [:])")
|
|
|
+ BFLog(message: "info = \(info ?? [:])")
|
|
|
if info?.keys.contains("PHImageResultIsDegradedKey") ?? false, "\(info?["PHImageResultIsDegradedKey"] ?? "0")" == "0" {
|
|
|
resultHandler(image, info)
|
|
|
}
|
|
@@ -718,7 +718,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
]
|
|
|
guard let imageSource = CGImageSourceCreateWithData(data as CFData, info as CFDictionary) else {
|
|
|
resultHandler(data, nil, nil)
|
|
|
- PQLog(message: "获取gifimageSource 失败")
|
|
|
+ BFLog(message: "获取gifimageSource 失败")
|
|
|
return
|
|
|
}
|
|
|
// 获取帧数
|
|
@@ -728,7 +728,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
for i in 0 ..< frameCount {
|
|
|
// 取出索引对应的图片
|
|
|
guard let imageRef = CGImageSourceCreateImageAtIndex(imageSource, i, info as CFDictionary) else {
|
|
|
- PQLog(message: "取出对应的图片失败")
|
|
|
+ BFLog(message: "取出对应的图片失败")
|
|
|
return
|
|
|
}
|
|
|
if frameCount == 1 {
|
|
@@ -738,12 +738,12 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
// 1.获取gif没帧的时间间隔
|
|
|
// 获取到该帧图片的属性字典
|
|
|
guard let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, i, nil) as? [String: Any] else {
|
|
|
- PQLog(message: "取出对应的图片属性失败")
|
|
|
+ BFLog(message: "取出对应的图片属性失败")
|
|
|
return
|
|
|
}
|
|
|
// 获取该帧图片中的GIF相关的属性字典
|
|
|
guard let gifInfo = properties[kCGImagePropertyGIFDictionary as String] as? [String: Any] else {
|
|
|
- PQLog(message: "取出对应的图片属性失败")
|
|
|
+ BFLog(message: "取出对应的图片属性失败")
|
|
|
return
|
|
|
}
|
|
|
let defaultFrameDuration = 0.1
|
|
@@ -753,7 +753,7 @@ class PQPHAssetVideoParaseUtil: NSObject {
|
|
|
let delayTime = gifInfo[kCGImagePropertyGIFDelayTime as String] as? NSNumber
|
|
|
let duration = unclampedDelayTime ?? delayTime
|
|
|
guard let frameDuration = duration else {
|
|
|
- PQLog(message: "获取帧时间间隔失败")
|
|
|
+ BFLog(message: "获取帧时间间隔失败")
|
|
|
return
|
|
|
}
|
|
|
// 对于播放时间低于0.011s的,重新指定时长为0.100s;
|