|  | @@ -10,7 +10,7 @@ import AVFoundation
 | 
	
		
			
				|  |  |  import VideoToolbox
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  public protocol PQMovieInputDelegate: AnyObject {
 | 
	
		
			
				|  |  | -    func didFinishMovie()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  public class PQMovieInput: ImageSource {
 | 
	
	
		
			
				|  | @@ -210,18 +210,43 @@ public class PQMovieInput: ImageSource {
 | 
	
		
			
				|  |  |   
 | 
	
		
			
				|  |  |   
 | 
	
		
			
				|  |  |          autoreleasepool {
 | 
	
		
			
				|  |  | -   
 | 
	
		
			
				|  |  | +            let duration = Double(Int(CMTimeGetSeconds(playeTimeRange.end) * 1000_000_000)) / 1000_000_000.0 // Only used for the progress block so its acuracy is not critical
 | 
	
		
			
				|  |  | +            self.currentTime = CMTimeMakeWithSeconds(self.beginTime +  CMTimeGetSeconds(startTime ?? CMTime.zero), preferredTimescale: 1000_000_000)
 | 
	
		
			
				|  |  |              self.beginTime = self.beginTime + 1 / 30
 | 
	
		
			
				|  |  | -            self.currentTime = CMTimeMakeWithSeconds(self.beginTime +  CMTimeGetSeconds(startTime ?? CMTime.zero), preferredTimescale: 600)
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            let currTime = CMTimeGetSeconds(self.currentTime)
 | 
	
		
			
				|  |  | +  
 | 
	
		
			
				|  |  | +            let prgressValue = currTime / Float64(duration)
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            FilterLog(message: "\(mIsExport) MovieOutput total frames appended:播放进行中 总用时: \(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0)) 播放器开始时间:\(CMTimeGetSeconds(playeTimeRange.start)) 播放器结束时间:\(duration)  总时间:\(CMTimeGetSeconds(playeTimeRange.end) - CMTimeGetSeconds(playeTimeRange.start)) 播放进度当前时间:\(currTime) 进度:\(prgressValue) 帧id \(totalFramesSent)")
 | 
	
		
			
				|  |  | +            totalFramesSent += 1
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +            FilterLog(message: "播放进行中 总用时: \(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0)) 播放进度当前时间:\(currTime) 进度:\(prgressValue)")
 | 
	
		
			
				|  |  | +            if currTime / duration > 1  {
 | 
	
		
			
				|  |  | +                FilterLog(message: "全部播放完成 总用时为:\(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0))")
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                self.completion?()
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | +                self.beginTime = 0
 | 
	
		
			
				|  |  | +                self.currentTime = .zero
 | 
	
		
			
				|  |  | +                self.isPlay = false
 | 
	
		
			
				|  |  | +                self.mAutoPause = true
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                // 定到首帧,最好移动到业务逻辑中。。。TODO不是导出模式才定帧
 | 
	
		
			
				|  |  | +                if !mIsExport {
 | 
	
		
			
				|  |  | +                    self.start(isFreeBuffer: true,timeRange: playeTimeRange)
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +          
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              if let movieOutput = self.synchronizedMovieOutput {
 | 
	
		
			
				|  |  |                  self.conditionLock.lock()
 | 
	
		
			
				|  |  |                  while self.readingShouldWait {
 | 
	
		
			
				|  |  |                      self.synchronizedEncodingDebugPrint("Disable reading")
 | 
	
		
			
				|  |  | -                    FilterLog(message: "Disable reading")
 | 
	
		
			
				|  |  | +                    FilterLog(message: "Disable reading 开始等待 \(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0)) ")
 | 
	
		
			
				|  |  |                      self.conditionLock.wait()
 | 
	
		
			
				|  |  | -                    FilterLog(message: "Enable reading")
 | 
	
		
			
				|  |  | +                    FilterLog(message: "Enable reading  停止等待 \(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0))")
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  self.conditionLock.unlock()
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -246,29 +271,7 @@ public class PQMovieInput: ImageSource {
 | 
	
		
			
				|  |  |                  self.start(isFreeBuffer: false)
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  | -            let duration = CMTimeGetSeconds(playeTimeRange.end) // Only used for the progress block so its acuracy is not critical
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            let currTime = CMTimeGetSeconds(self.currentTime)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            let prgressValue = currTime / duration
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            FilterLog(message: "播放进行中 总用时: \(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0)) 播放进度当前时间:\(currTime) 进度:\(prgressValue)")
 | 
	
		
			
				|  |  | -            if prgressValue > 1 {
 | 
	
		
			
				|  |  | -                FilterLog(message: "全部播放完成 总用时为:\(CFAbsoluteTimeGetCurrent() - (debugStartTime ?? 0.0))")
 | 
	
		
			
				|  |  | - 
 | 
	
		
			
				|  |  | -                self.delegate?.didFinishMovie()
 | 
	
		
			
				|  |  | -                self.completion?()
 | 
	
		
			
				|  |  | - 
 | 
	
		
			
				|  |  | -                self.beginTime = 0
 | 
	
		
			
				|  |  | -                self.currentTime = .zero
 | 
	
		
			
				|  |  | -                self.isPlay = false
 | 
	
		
			
				|  |  | -                self.mAutoPause = true
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                // 定到首帧,最好移动到业务逻辑中。。。TODO不是导出模式才定帧
 | 
	
		
			
				|  |  | -                if !mIsExport {
 | 
	
		
			
				|  |  | -                    self.start(isFreeBuffer: true,timeRange: playeTimeRange)
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +          
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  //        }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -439,10 +442,9 @@ public class PQMovieInput: ImageSource {
 | 
	
		
			
				|  |  |              let start =  CMTimeGetSeconds(playeTimeRange.start)
 | 
	
		
			
				|  |  |              let currTime = CMTimeGetSeconds(currentTime)
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  | -   
 | 
	
		
			
				|  |  | -            
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |              let prgressValue = (currTime - start) / (duration - start)
 | 
	
		
			
				|  |  | -            FilterLog(message: " movinput 当前时间 is \(currTime) 当前进度:\(prgressValue)")
 | 
	
		
			
				|  |  | +            FilterLog(message: "\(mIsExport) movinput 当前时间 is \(currTime) 当前进度:\(prgressValue)")
 | 
	
		
			
				|  |  |              progress?(currTime, duration, prgressValue)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              sharedImageProcessingContext.runOperationSynchronously {
 | 
	
	
		
			
				|  | @@ -494,7 +496,7 @@ public class PQMovieInput: ImageSource {
 | 
	
		
			
				|  |  |              let startTime = CFAbsoluteTimeGetCurrent()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              imageFramebuffer.lock()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +            BFLog(message: "mIsExport:\(mIsExport) 实际设置的每一帧时间戳:\(CMTimeGetSeconds(currentTime))")
 | 
	
		
			
				|  |  |              // 设置当前帧的时间戳
 | 
	
		
			
				|  |  |              imageFramebuffer.timingStyle = .videoFrame(timestamp: Timestamp(currentTime))
 | 
	
		
			
				|  |  |   
 | 
	
	
		
			
				|  | @@ -564,7 +566,9 @@ public class PQMovieInput: ImageSource {
 | 
	
		
			
				|  |  |          if movieOutput.assetWriterVideoInput.isReadyForMoreMediaData || movieOutput.assetWriterAudioInput?.isReadyForMoreMediaData ?? false {
 | 
	
		
			
				|  |  |              readingShouldWait = false
 | 
	
		
			
				|  |  |              conditionLock.signal()
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  | +            BFLog(message: "MovieOutput total frames appended 要加锁了")
 | 
	
		
			
				|  |  |              readingShouldWait = true
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          conditionLock.unlock()
 |