2

I'm developing an app in iOS. I need to capture video from the camera and I need to record that video to a file and also get the uncompressed frames, that's why I need to use both AVCaptureOutput...

I read this in the apple's documentation "You can configure multiple inputs and outputs, coordinated by a single session:" So I think it must be doable, but I'm having problems with it...

I'm setting both to the session doing:

self.fileOutput.maxRecordedDuration =  CMTimeMake(5000,1 );;
self.fileOutput.minFreeDiskSpaceLimit = 3000;


if([self.captureSession canAddOutput:self.fileOutput]){
    [self.captureSession addOutput:self.fileOutput];
    NSLog(@"Added File Video Output");
}else{
    NSLog(@"Couldn't add video output");
}

if ([self.captureSession canAddOutput:videoOutput]){
    [self.captureSession addOutput:videoOutput];
    NSLog(@"Added Data Video Output");
}else{
    NSLog(@"Couldn't add video output");
}

I'm getting both 'positive' confirmation messages. After that I'm calling to:

NSString *assetPath         = [self createAssetFilePath:@"mov"];
NSURL *outputURL            = [[NSURL alloc] initFileURLWithPath:assetPath];
[self.fileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
[self.captureSession startRunning];

And then I have my delegate function:

- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error {

NSLog(@"Output File URL: %@ ", outputFileURL);

BOOL recordedSuccessfully = YES;

    if ([error code] != noErr) {

        NSLog(@"Error: %@", error);
        id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
        NSLog(@"Error: %@", value);
        if (value) {
            recordedSuccessfully = [value boolValue];
        }

    }
}

And I'm getting no error, but the "AVCaptureVideoDataOutput" was working before adding the "AVCaptureMovieFileOutput" and now it's not...

So... Is that possible to do both?! Any idea?!

Thanks!

Andres
  • 11,439
  • 12
  • 48
  • 87

1 Answers1

4

The answer to this question: Simultaneous AVCaptureVideoDataOutput and AVCaptureMovieFileOutput indicates that you cannot have an AVCaptureVideoDataOutput and a AVCaptureMovieFileOutput to your session simultaneously. I can't verify this in the Apple documentation unfortunately. My experience is that I no longer receive messages to my AVCaptureVideoDataOutput's sampleBufferDelegate after I add an AVCaptureMovieFileOutput to the session's output, which seemingly backs up that assertion.

Community
  • 1
  • 1
PixelCloudSt
  • 2,805
  • 1
  • 18
  • 19