1

iOSのドキュメントによると、セッションの実行中に入力を追加および削除できます。たとえば、フロント カメラとバック カメラを切り替えることができます。

ただし、これを試すと、セッションが停止します。beginConfiguration次のようにcommitConfiguration呼び出してセッションをロックしています。

- (void)switchCamera:(UIButton *)sender {

    dispatch_async([self sessionQueue], ^{

        AVCaptureSession *session = self.captureSession;
        [session beginConfiguration];

        AVCaptureInput *currentInput = self.currentCameraIsBack ? self.videoDeviceInputBack : self.videoDeviceInputFront;
        AVCaptureInput *newInput = self.currentCameraIsBack ? self.videoDeviceInputFront : self.videoDeviceInputBack;

        [session removeInput:currentInput];
        [session addInput:newInput];
        self.currentCameraIsBack = !self.currentCameraIsBack;

        [session setSessionPreset:AVCaptureSessionPresetMedium];
        [self setCameraOutputProperties];

        [session commitConfiguration];
    });
}

に出力していAVCaptureMovieFileOutputます。このセッションを切り替え可能に構成するために必要なことはありますか?

(この質問のOPは、古い入力を削除せずに新しい入力を追加しようとしていることに注意してください。これはここでは問題ではありません)

4

1 に答える 1

0

これを行うには、AVAssetWriter を使用し、次のようにappendSampleBuffer:自分自身を呼び出す必要があることがわかりましCMSampleBufferた。

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {

    if (self.recording && self.videoWriterInput.isReadyForMoreMediaData) {

        [self.videoWriterInput appendSampleBuffer:sampleBuffer];
    }
}
于 2015-05-13T15:32:28.673 に答える