如何记录Avcapture Record启动的确切时间戳?

时间:2017-03-20 09:39:04

标签: ios objective-c timestamp avcapturesession 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];

1 个答案:

答案 0 :(得分: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

希望它有所帮助。

干杯。