private AVCaptureDeviceFormat SelectFormatForDevice(AVCaptureDevice device, int targetWidth, int targetHeight) { var formats = RTCCameraVideoCapturer.SupportedFormatsForDevice(device); AVCaptureDeviceFormat selectedFormat = null; var currentDiff = int.MaxValue; foreach (var format in formats) { if (!(format.FormatDescription is CMVideoFormatDescription videoFormatDescription)) { continue; } var dimension = videoFormatDescription.Dimensions; var pixelFormat = videoFormatDescription.MediaSubType; var diff = Math.Abs(targetWidth - dimension.Width) + Math.Abs(targetHeight - dimension.Height); if (diff < currentDiff) { selectedFormat = format; currentDiff = diff; } else if (diff == currentDiff && pixelFormat == _capturer.PreferredOutputPixelFormat) { selectedFormat = format; } } return(selectedFormat); }
private static int SelectFpsForFormat(AVCaptureDeviceFormat format) { var maxSupportedFramerate = format.VideoSupportedFrameRateRanges.Select(fpsRange => fpsRange.MaxFrameRate) .Prepend(0d).Max(); return((int)Math.Min(maxSupportedFramerate, FramerateLimit)); }
private int SelectFpsForFormat(AVCaptureDeviceFormat format) { var maxSupportedFramerate = 0d; foreach (var fpsRange in format.VideoSupportedFrameRateRanges) { maxSupportedFramerate = Math.Max(maxSupportedFramerate, fpsRange.MaxFrameRate); } return((int)Math.Min(maxSupportedFramerate, kFramerateLimit)); }
private int GetFpsByFormat(AVCaptureDeviceFormat format) { var maxSupportedFps = 0d; foreach (var fpsRange in format.VideoSupportedFrameRateRanges) { maxSupportedFps = Math.Max(maxSupportedFps, fpsRange.MaxFrameRate); } return((int)Math.Min(maxSupportedFps, _frameRateLimit)); }
private void StartCameraWithCompletionHandler(Action <bool, NSError> completion) { captureSession = new AVCaptureSession(); captureSession.BeginConfiguration(); captureDevice = CameraDeviceForPosition(AVCaptureDevicePosition.Back); if (captureDevice == null) { string message = "Error message back camera - not found"; string title = "Error title back camera - not found"; ShowErrorMessage(message, title); return; } NSError error; AVCaptureDeviceInput deviceInput = AVCaptureDeviceInput.FromDevice(captureDevice, out error); if (deviceInput == null) { Console.WriteLine("This error should be handled appropriately in your app -- obtain device input: {0}", error); string message = "Error message back camera - can't open."; string title = "Error title for back camera - can't open."; ShowErrorMessage(message, title); return; } captureSession.AddInput(deviceInput); stillImageOutput = new AVCaptureStillImageOutput(); //Or instead of JPEG, we can use one of the following pixel formats: BGRA, 420f output stillImageOutput.OutputSettings = NSDictionary.FromObjectAndKey(AVVideo.CodecJPEG, AVVideo.CodecKey); captureSession.AddOutput(stillImageOutput); cameraPreviewView.ConfigureCaptureSession(captureSession, stillImageOutput); captureSession.SessionPreset = AVCaptureSession.PresetPhoto; captureDeviceFormat = captureDevice.ActiveFormat; captureSession.CommitConfiguration(); captureSession.StartRunning(); maxBracketCount = stillImageOutput.MaxBracketedCaptureStillImageCount; PrepareBracketsWithCompletionHandler(completion); }
private void StartCameraWithCompletionHandler(Action<bool, NSError> completion) { captureSession = new AVCaptureSession (); captureSession.BeginConfiguration (); captureDevice = CameraDeviceForPosition (AVCaptureDevicePosition.Back); if (captureDevice == null) { string message = "Error message back camera - not found"; string title = "Error"; ShowErrorMessage (message, title); return; } NSError error; AVCaptureDeviceInput deviceInput = AVCaptureDeviceInput.FromDevice (captureDevice, out error); if (deviceInput == null) { Console.WriteLine ("This error should be handled appropriately in your app -- obtain device input: {0}", error); string message = "Error message back camera - can't open."; string title = "Error"; ShowErrorMessage (message, title); return; } captureSession.AddInput (deviceInput); stillImageOutput = new AVCaptureStillImageOutput (); //Or instead of JPEG, we can use one of the following pixel formats: BGRA, 420f output stillImageOutput.OutputSettings = new NSDictionary (AVVideo.CodecKey, AVVideo.CodecJPEG); captureSession.AddOutput (stillImageOutput); cameraPreviewView.ConfigureCaptureSession (captureSession, stillImageOutput); captureSession.SessionPreset = AVCaptureSession.PresetPhoto; captureDeviceFormat = captureDevice.ActiveFormat; captureSession.CommitConfiguration (); captureSession.StartRunning (); maxBracketCount = stillImageOutput.MaxBracketedCaptureStillImageCount; PrepareBracketsWithCompletionHandler (completion); }