を使用して画面を記録しようとしています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);
}
ドキュメンテーションによると
このメソッドは、ファイル出力が特定の接続から 1 つのサンプル バッファー (たとえば、1 つのビデオ フレームまたはオーディオ バッファー) を受信するたびに呼び出されます。これにより、デリゲートは正確なサンプル境界で記録を開始および停止したり、出力ファイルを変更したりできます。このメソッド内から呼び出された場合、ファイル出力の 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