0

Am using AVCapture to recording the video and storing in documents directory.

Right now We are storing the start time of video recording on click of the recording button click.

We are observing some delay in milliseconds between the click of recording button and the actual recording file.

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];
       }

Can anyone guide that how we can to store the exact starting recording time (With date time with Hours,Minutes,seconds,Milliseconds)of the video with accuracy in milliseconds?

Following is the code that we are storing the date of start recording just before start capturing the output.

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

1 Answers1

1

Why don't you use AVCaptureFileOutputRecordingDelegate methods to determine the time for all the operations? Check the list of delegate methods iOS have as follows

- (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
}

Check others here.

Hope it helps.

Cheers.

iphonic
  • 12,615
  • 7
  • 60
  • 107