【问题标题】:How to record the exact time stamp for Avcapture Record starts?如何记录 Avcapture Record 开始的确切时间戳?
【发布时间】:2017-03-20 09:39:03
【问题描述】:

我正在使用 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];

【问题讨论】:

    标签: ios objective-c timestamp avcapturesession avcapture


    【解决方案1】:

    为什么不使用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

    希望对你有帮助。

    干杯。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多