/// <summary> /// Finds all the available video resolutions that match the aspect ratio of the preview stream /// Note: This should also be done with photos as well. This same method can be modified for photos /// by changing the MediaStreamType from VideoPreview to Photo. /// </summary> private void MatchPreviewAspectRatio() { // Query all properties of the device IEnumerable <StreamResolution> allVideoProperties = _previewer.MediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord).Select(x => new StreamResolution(x)); // Query the current preview settings StreamResolution previewProperties = new StreamResolution(_previewer.MediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview)); // Get all formats that have the same-ish aspect ratio as the preview, and find the highest resolution one // Allow for some tolerance in the aspect ratio comparison const double ASPECT_RATIO_TOLERANCE = 0.015; var matchingFormats = allVideoProperties.Where(x => Math.Abs(x.AspectRatio - previewProperties.AspectRatio) < ASPECT_RATIO_TOLERANCE); // Order them by resolution then frame rate allVideoProperties = matchingFormats.OrderByDescending(x => x.Height * x.Width).ThenByDescending(x => x.FrameRate); // Clear out old entries and populate the video combo box with new matching entries VideoSettings.Items.Clear(); foreach (var property in allVideoProperties) { ComboBoxItem comboBoxItem = new ComboBoxItem(); comboBoxItem.Content = property.GetFriendlyName(); comboBoxItem.Tag = property; VideoSettings.Items.Add(comboBoxItem); } VideoSettings.SelectedIndex = -1; }
/// <summary> /// Finds all the available video resolutions that match the aspect ratio of the preview stream /// Note: This should also be done with photos as well. This same method can be modified for photos /// by changing the MediaStreamType from VideoPreview to Photo. /// </summary> private void MatchPreviewAspectRatio() { // Query all properties of the device IEnumerable<StreamResolution> allVideoProperties = _previewer.MediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoRecord).Select(x => new StreamResolution(x)); // Query the current preview settings StreamResolution previewProperties = new StreamResolution(_previewer.MediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview)); // Get all formats that have the same-ish aspect ratio as the preview // Allow for some tolerance in the aspect ratio comparison const double ASPECT_RATIO_TOLERANCE = 0.015; var matchingFormats = allVideoProperties.Where(x => Math.Abs(x.AspectRatio - previewProperties.AspectRatio) < ASPECT_RATIO_TOLERANCE); // Order them by resolution then frame rate allVideoProperties = matchingFormats.OrderByDescending(x => x.Height * x.Width).ThenByDescending(x => x.FrameRate); // Clear out old entries and populate the video combo box with new matching entries VideoSettings.Items.Clear(); foreach (var property in allVideoProperties) { ComboBoxItem comboBoxItem = new ComboBoxItem(); comboBoxItem.Content = property.GetFriendlyName(); comboBoxItem.Tag = property; VideoSettings.Items.Add(comboBoxItem); } VideoSettings.SelectedIndex = -1; }