Simultaneous AVCaptureVideoDataOutput and AVCaptureMovieFileOutput
I have contacted an engineer at Apple's support and he told me that simultaneous AVCaptureVideoDataOutput
+ AVCaptureMovieFileOutput
use is not supported. I don't know if they will support it in the future, but he used the word "not supported at this time".
I encourage you to fill a bug report / feature request on this, as I did (bugreport.apple.com), as they measure how hard people want something and we perhaps can see this in a near future.
Although you cannot use AVCaptureVideoDataOutput
, you can use AVCaptureVideoPreviewLayer
simultaneously with AVCaptureMovieFileOutput
. See the "AVCam" example on Apple's Website.
In Xamarin.iOS, the code looks like this:
var session = new AVCaptureSession();
var camera = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
var mic = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Audio);
if(camera == null || mic == null){
throw new Exception("Can't find devices");
}
if(session.CanAddInput(camera)){
session.AddInput(camera);
}
if(session.CanAddInput(mic)){
session.AddInput(mic);
}
var layer = new AVCaptureVideoPreviewLayer(session);
layer.LayerVideoGravity = AVLayerVideoGravity.ResizeAspectFill;
layer.VideoGravity = AVCaptureVideoPreviewLayer.GravityResizeAspectFill;
cameraView = new UIView();
cameraView.Layer.AddSublayer(layer);
var filePath = System.IO.Path.Combine( Path.GetTempPath(), "temporary.mov");
var fileUrl = NSUrl.FromFilename( filePath );
var movieFileOutput = new AVCaptureMovieFileOutput();
var recordingDelegate = new MyRecordingDelegate();
session.AddOutput(movieFileOutput);
movieFileOutput.StartRecordingToOutputFile( fileUrl, recordingDelegate);
Still 9 years later Apple apparently does not seem to want this to work together.
But you can easily work with AVAssetWriter.
You can't use AVCaptureVideoDataOutput and AVCaptureMovieFileOutput on the same time. But you can use AVCaptureVideoDataOutput and analyse or modify on the data, then use AVAsseWriter to write the frames to a file.
Source: https://developer.apple.com/forums/thread/98113
How to save video with output using AVAssetWriter:
Save AVCaptureVideoDataOutput to movie file using AVAssetWriter in Swift