2

I am trying to record screen using AVFoundation Framework. The issue i am having is when i stop recording just after few frames i got an error AVErrorNoDataCaptured = -11805 where i can clearly see frames were captured as captureOutput:didDropSampleBuffer:fromConnection:

my settings are as follow

[self.captureSession beginConfiguration]; //AVCaptureSession *captureSession;
[self.captureScreenInput setCropRect:rect]; //AVCaptureScreenInput *captureScreenInput
[self.captureScreenInput setCapturesMouseClicks:captureMouseClicks];
[self.captureScreenInput setScaleFactor:2.f/[[NSScreen mainScreen] backingScaleFactor]];
[self.captureScreenInput setMinFrameDuration:CMTimeMake(1,15)];
[self.captureScreenInput setRemovesDuplicateFrames:YES];
[_captureSession commitConfiguration];

.

-(void)captureOutput:(AVCaptureFileOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
    static int i = 0;
    NSLog(@"Frame: %d", ++i);
    CMTime recTime = [_captureMovieFileOutput recordedDuration];
    if(recTime.timescale > 0)
        NSLog(@"Time Value: %lld Seconds:: %lld ",recTime.value, recTime.value/recTime.timescale);
    NSLog(@"Size: %lld Kb",[_captureMovieFileOutput recordedFileSize]/1024);
} 

Documentation says

This method is called whenever the file output receives a single sample buffer (a single video frame or audio buffer, for example) from the given connection. This gives delegates an opportunity to start and stop recording or change output files at an exact sample boundary. If called from within this method, the file output’s startRecordingToOutputFileURL:recordingDelegate: and resumeRecording methods are guaranteed to include the received sample buffer in the new file, whereas calls to stopRecording and pauseRecording are guaranteed to include all samples leading up to those in the current sample buffer in the existing file.

So what is the problem here why can't i have a video of fewer frames. Output log for frame is as follow

 Frame: 1
 Size: 0 Kb
 Frame: 2
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 3
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 4
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 5
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 6
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 7
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 8
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 9
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 10
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Frame: 11
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Time Value: 0 Seconds:: 0 
 Size: 0 Kb
 Not Recording
 Frame: 12
 Size: 0 Kb
 Frame: 13
 Size: 0 Kb
 Frame: 14
 Size: 0 Kb
 Frame: 15
 Size: 0 Kb
Mirza Bilal
  • 891
  • 11
  • 34

0 Answers0