Umschalten der AVCaptureSession-Voreinstellung beim Aufnehmen eines Fotos

Mein aktuelles Setup ist wie folgt (basierend auf dem ColorTrackingCamera Projekt vonBrad Larson):

Ich benutze eineAVCaptureSession einstellenAVCaptureSessionPreset640x480 wofür ich die Ausgabe als Textur durch eine OpenGL-Szene laufen lasse. Diese Textur wird dann von einem Fragment-Shader bearbeitet.

Ich benötige diese Voreinstellung für "geringere Qualität", weil ich eine hohe Bildrate beibehalten möchte, wenn der Benutzer eine Vorschau anzeigt. Ich möchte dann zu einer Ausgabe mit höherer Qualität wechseln, wenn der Benutzer ein Standbild aufnimmt.

Zuerst dachte ich, ich könnte das ändernsessionPreset auf derAVCaptureSession Dies zwingt die Kamera jedoch dazu, neu zu fokussieren, was die Benutzerfreundlichkeit beeinträchtigt.

[captureSession beginConfiguration];
captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
[captureSession commitConfiguration];

Momentan versuche ich eine Sekunde hinzuzufügenAVCaptureStillImageOutput zur AVCaptureSession, aber ich bekomme einen leeren Pixelpuffer, also glaube ich, dass ich irgendwie festgefahren bin.

Hier ist mein Session-Setup-Code:

...

// Add the video frame output
[captureSession beginConfiguration];

videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[videoOutput setAlwaysDiscardsLateVideoFrames:YES];
[videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
[videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

if ([captureSession canAddOutput:videoOutput])
{
    [captureSession addOutput:videoOutput];
}
else
{
    NSLog(@"Couldn't add video output");
}

[captureSession commitConfiguration];



// Add still output
[captureSession beginConfiguration];
stillOutput = [[AVCaptureStillImageOutput alloc] init];

if([captureSession canAddOutput:stillOutput])
{
    [captureSession addOutput:stillOutput];
}
else
{
    NSLog(@"Couldn't add still output");
}

[captureSession commitConfiguration];



// Start capturing
[captureSession setSessionPreset:AVCaptureSessionPreset640x480];
if(![captureSession isRunning])
{
    [captureSession startRunning];
};

...

Und hier ist meine Erfassungsmethode:

- (void)prepareForHighResolutionOutput
{
    AVCaptureConnection *videoConnection = nil;
    for (AVCaptureConnection *connection in stillOutput.connections) {
        for (AVCaptureInputPort *port in [connection inputPorts]) {
            if ([[port mediaType] isEqual:AVMediaTypeVideo] ) {
                videoConnection = connection;
                break;
            }
        }
        if (videoConnection) { break; }
    }

    [stillOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:
     ^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
         CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(imageSampleBuffer);
         CVPixelBufferLockBaseAddress(pixelBuffer, 0);
         int width = CVPixelBufferGetWidth(pixelBuffer);
         int height = CVPixelBufferGetHeight(pixelBuffer);

         NSLog(@"%i x %i", width, height);
         CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
     }];
}

(width undheight entpuppen sich als 0)

Ich habe die Dokumente der AVFoundation-Dokumentation durchgelesen, aber anscheinend erhalte ich nichts Wesentliches.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage