Browse Source

缩略图计算

harry 3 years ago
parent
commit
c6e93ac4ea

+ 7 - 7
BFRecordScreenKit/Classes/BFRecordItemModel.swift

@@ -135,11 +135,11 @@ public class BFRecordItemModel: NSObject {
     }
     
     /// 视频分解成帧
-    /// - parameter fps                          : 自定义帧数 每秒内取的帧数
+    /// - parameter frames                          : 需要取的帧数
     /// - parameter firstImagesCount             : 获取首先N张连续视频帧后先返回给调用方使用作为缓冲
     /// - parameter splitCompleteClosure    : 回调
-    func splitVideoFileUrlFps(fps: Double, firstImagesCount:Int = 0, splitCompleteClosure: @escaping ((Bool, [UIImage]) -> Void)) {
-        guard let localPath = localPath else {
+    func splitVideoFileUrlFps(frames: Int, firstImagesCount:Int = 0, splitCompleteClosure: @escaping ((Bool, [UIImage]) -> Void)) {
+        guard let urlAsset = videoAsset, urlAsset.duration.seconds > 0 else {
             return
         }
 
@@ -147,11 +147,11 @@ public class BFRecordItemModel: NSObject {
 
         var times = [NSValue]()
 
-        let urlAsset = AVURLAsset(url: URL(fileURLWithPath: localPath))
+//        let urlAsset = AVURLAsset(url: URL(fileURLWithPath: localPath))
         let start = 0
-        let end = Int(urlAsset.duration.seconds * Float64(fps))
-
-        for i in start...end {
+//        let end = Int(urlAsset.duration.seconds * Float64(fps))
+        let fps = Double(frames) / urlAsset.duration.seconds
+        for i in start..<frames {
             let timeValue = NSValue(time: CMTimeMake(value: Int64(i * 1000), timescale: Int32(fps * 1000)))
 
             times.append(timeValue)

+ 2 - 2
BFRecordScreenKit/Classes/RecordScreen/View/BFVideoThumbProgressView.swift

@@ -122,8 +122,8 @@ class BFVideoThumbProgressView: UIView {
                 make.width.equalTo(CGFloat(count) * thumbImageWidth).priority(.high)
             }
             
-            let fps = Double(count) / dur
-            recordItem!.splitVideoFileUrlFps(fps: fps, firstImagesCount: Int(ceil(width/2.0/thumbImageWidth))) { [weak self, weak recordItem] hadGetAll, images in
+            
+            recordItem!.splitVideoFileUrlFps(frames: count, firstImagesCount: Int(ceil(width/2.0/thumbImageWidth))) { [weak self, weak recordItem] hadGetAll, images in
                 guard let sself = self, let sitem = recordItem else {
                     return
                 }