1

I am using this code, to create AVCaptureSession, but when -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection is called, sampleBuffer size is 0

- (BOOL)createCaptureSession:(NSError **)outError{
/* Create a capture session. */
self.captureSession = [[AVCaptureSession alloc] init];
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPresetHigh])
{
    /* Specifies capture settings suitable for high quality video and audio output. */
    [self.captureSession setSessionPreset:AVCaptureSessionPresetHigh];
}

/* Add the main display as a capture input. */
display = CGMainDisplayID();
self.captureScreenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:display];
if ([self.captureSession canAddInput:self.captureScreenInput])
{
    [self.captureSession addInput:self.captureScreenInput];
}
else
{   NSLog(@"nevyslo");
    return NO;
}

/* Register for notifications of errors during the capture session so we can display an alert. */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionRuntimeErrorDidOccur:) name:AVCaptureSessionRuntimeErrorNotification object:self.captureSession];


AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[self.captureSession addOutput:output];

dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];

[self.captureSession startRunning];
    return YES;
}

Is there anything wrong in my method? Is it possible that mistake could be somewhere else ? I am using ARC.

EDIT Buffer was not empty, but it got deallocated imediatelly. Solved by retaining buffer. Thanks

Heisenbug
  • 951
  • 6
  • 25
  • What do you want to do with the sample buffer? You should include your `captureOutput: didOutputSampleBuffer:fromConnection:` method in the question. – Rhythmic Fistman Nov 22 '15 at 23:17

0 Answers0