AVFoundation - How to use beginConfiguration and commitConfiguration to change AVCaptureMovieFileOutput settings?

StackOverflow https://stackoverflow.com/questions/16160252

سؤال

The Apple documentation for AVCaptureSession's beginConfiguration and commitConfiguration says that

After calling beginConfiguration, you can for example add or remove outputs, alter the sessionPreset, or configure individual capture input or output properties.

I'm specifically looking to use the "configure output properties" part. In particular, I would like to use the atomic configuration change to stop recording on one AVCaptureMovieFileOutput and start recording on another. Unfortunately, this doesn't seem to be working. What I'm specifically trying is the following code:

NSLog(@" = %d", [[self output] isRecording]);
NSLog(@" = %d", [[self output2] isRecording]);

[[self session] beginConfiguration];
[[self output] stopRecording];
[[self session] removeOutput:output];
[[self session] addOutput:output2];
outputFileURL = [self getMovieSaveURL];
[[self output2] startRecordingToOutputFileURL:outputFileURL recordingDelegate:self];
[[self session] commitConfiguration];

NSLog(@" = %d", [[self output] isRecording]);
NSLog(@" = %d", [[self output2] isRecording]);

However, from the NSLog statements I've placed in the code, I see that the first output is still recording and the second one still isn't even after the commit. Any ideas how I can make this work? Thank you much!

هل كانت مفيدة؟

المحلول

You can decouple the capture and the file writing by using an AVCaptureOutput and an AVAssetWriter. Then all capture data arrives at a callback in your app, and you can then pass it to the correct instance of the asset writer. There's a sample that shows something very similar at http://www.gdcl.co.uk/2013/02/20/iPhone-Pause.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top