我正在尝试使用AVFoundation Framework
录制屏幕。我遇到的问题是当我在几帧之后停止录制时出现错误AVErrorNoDataCaptured = -11805
我可以清楚地看到帧被捕获为captureOutput:didDropSampleBuffer:fromConnection:
我的设置如下
[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);
}
文档说
只要文件输出从给定连接接收单个样本缓冲区(例如,单个视频帧或音频缓冲区),就会调用此方法。这使代表有机会在精确的样本边界处开始和停止记录或更改输出文件。如果在此方法中调用,则文件输出的startRecordingToOutputFileURL:recordingDelegate:和resumeRecording方法保证在新文件中包含接收的样本缓冲区,而对stopRecording和pauseRecording的调用保证包括所有样本直到现有文件中当前样本缓冲区中的那些。
那么这里有什么问题为什么我不能拥有更少帧的视频。帧的输出日志如下
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