2017-03-20 133 views
0

正在使用AVCapture錄製視頻並存儲在文檔目錄中。如何記錄Avcapture記錄的確切時間戳?

現在我們正在點擊錄製按鈕點擊來存儲視頻錄製的開始時間。

我們正在觀察點擊錄製按鈕和實際錄製文件之間的一些延遲時間(以毫秒爲單位)。

dispatch_async(sessionQueue, ^{ 
     if (! self.movieFileOutput.isRecording) { 
      // Update the orientation on the movie file output video connection before starting recording. 
      AVCaptureConnection *movieFileOutputConnection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo]; 
      movieFileOutputConnection.videoOrientation = videoPreviewLayerVideoOrientation; 

      // Start recording to a temporary file. 
      NSString *outputFileName = [NSUUID UUID].UUIDString; 
      NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[outputFileName stringByAppendingPathExtension:@"mov"]]; 

      dispatch_async(dispatch_get_main_queue(), ^{ 
       VideoInfo *info = [dbManager getVideoWithId:self.currentVideoID]; 
       if (info == nil) { 
        VideoInfo *tempVid = [[VideoInfo alloc] init]; 
        tempVid.videoId = (int)[tempVid generateVideoID]; 
        [dbManager insertVideoDetails:tempVid]; 
        info = tempVid; 
       } 

       [appDelegate.realm beginWriteTransaction]; 
       info.videoDate = [NSString stringWithFormat:@"%lld",[@(floor([[NSDate date] timeIntervalSince1970] * 1000000)) longLongValue]]; 
       [appDelegate.realm commitWriteTransaction]; 
      }); 
// 
      [self.movieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputFilePath] recordingDelegate:self]; 

      // Setup socket connection 
//   [[SocketManager sharedManager] socketThreadStart]; 
      [[SocketManager sharedManager] setupSocket]; 
     } 

任何人都可以指導我們如何能保存準確的開始記錄時間(含日期時間具時,分,秒,毫秒)以毫秒精度的視頻?

以下是我們在開始捕獲輸出之前存儲開始記錄日期的代碼。

info.videoDate = [NSString stringWithFormat:@"%lld",[@(floor([[NSDate date] timeIntervalSince1970] * 1000000)) longLongValue]]; 
        [appDelegate.realm commitWriteTransaction]; 
       }); 
       [self.movieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputFilePath] recordingDelegate:self]; 

回答

0

你爲什麼不使用AVCaptureFileOutputRecordingDelegate方法來確定所有的操作時間?檢查委託方法的iOS的名單有如下

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didStartRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections{ 
     //WHEN RECORDING STARTED 
} 

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error{ 
     //WHEN RECORDING ENDED 
} 

檢查他人here

希望它有幫助。

乾杯。