summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-11-30 14:54:11 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-05 14:13:24 +0000
commit457323870c8cfb941d55cbdbe801015ffd82aea7 (patch)
treea03700ebbce5d816d6f5b415a8e18fcabd3c8dad
parent68a3ea85e9a9c28a3875367deb48b460585a79e8 (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 Change-Id: I5e043188a4ed3d4acd72190b96fba4095a3f9aa2 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit c76508f8a2d121a428d90648b4c894c845c3f010) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/multimediawidgets/camera/camera.cpp24
-rw-r--r--src/multimedia/platform/qplatformcamera.cpp3
2 files changed, 14 insertions, 13 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());
}
}
diff --git a/src/multimedia/platform/qplatformcamera.cpp b/src/multimedia/platform/qplatformcamera.cpp
index 21a13ea97..ac8793fb0 100644
--- a/src/multimedia/platform/qplatformcamera.cpp
+++ b/src/multimedia/platform/qplatformcamera.cpp
@@ -72,7 +72,8 @@ QCameraFormat QPlatformCamera::findBestCameraFormat(const QCameraDevice &camera)
for (const auto &fmt : formats) {
// check if fmt is better. We try to find the highest resolution that offers
// at least 30 FPS
- if (f.maxFrameRate() < 30 && fmt.maxFrameRate() > f.maxFrameRate())
+ // we use 29 FPS to compare against as some cameras report 29.97 FPS...
+ if (f.maxFrameRate() < 29 && fmt.maxFrameRate() > f.maxFrameRate())
f = fmt;
else if (f.maxFrameRate() == fmt.maxFrameRate() &&
f.resolution().width()*f.resolution().height() < fmt.resolution().width()*fmt.resolution().height())