summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-11-30 14:54:11 +0100
committerLars Knoll <lars.knoll@qt.io>2022-01-05 14:28:17 +0100
commitc76508f8a2d121a428d90648b4c894c845c3f010 (patch)
tree6778e0b59968ac25312b3f9b24582a55963d2d9b /examples
parent9ea19cc787a049347f840a3e0560bd537b740dfa (diff)
Fix the camera format used by the camera example
The camera example was simply trying to get the format with the highest possible resolution. But that often lead to formats with a very low frame rate being chosen. Change the algorithm to find the highest resolution format with at least 30FPS. Fixes: QTBUG-97817 Pick-to: 6.2 6.3 Change-Id: I5e043188a4ed3d4acd72190b96fba4095a3f9aa2 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/multimediawidgets/camera/camera.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/examples/multimediawidgets/camera/camera.cpp b/examples/multimediawidgets/camera/camera.cpp
index e87ef47f1..e71e209f3 100644
--- a/examples/multimediawidgets/camera/camera.cpp
+++ b/examples/multimediawidgets/camera/camera.cpp
@@ -133,22 +133,22 @@ void Camera::setCamera(const QCameraDevice &cameraDevice)
updateCaptureMode();
if (m_camera->cameraFormat().isNull()) {
- // Setting default settings.
- // The biggest resolution and the max framerate
auto formats = cameraDevice.videoFormats();
if (!formats.isEmpty()) {
- auto defaultFormat = formats.first();
-
- for (const auto &format : formats) {
-
- bool isFormatBigger = format.resolution().width() > defaultFormat.resolution().width()
- && format.resolution().height() > defaultFormat.resolution().height();
-
- defaultFormat = isFormatBigger ? format : defaultFormat;
+ // Choose a decent camera format: Maximum resolution at at least 30 FPS
+ // we use 29 FPS to compare against as some cameras report 29.97 FPS...
+ QCameraFormat bestFormat;
+ for (const auto &fmt : formats) {
+ if (bestFormat.maxFrameRate() < 29 && fmt.maxFrameRate() > bestFormat.maxFrameRate())
+ bestFormat = fmt;
+ else if (bestFormat.maxFrameRate() == fmt.maxFrameRate() &&
+ bestFormat.resolution().width()*bestFormat.resolution().height() <
+ fmt.resolution().width()*fmt.resolution().height())
+ bestFormat = fmt;
}
- m_camera->setCameraFormat(defaultFormat);
- m_mediaRecorder->setVideoFrameRate(defaultFormat.maxFrameRate());
+ m_camera->setCameraFormat(bestFormat);
+ m_mediaRecorder->setVideoFrameRate(bestFormat.maxFrameRate());
}
}