How to get camera supported resolutions using Qt5?
-
I tried it again calling the "load()":http://qt-project.org/doc/qt-5/qcamera.html#load method:
@
QList<QByteArray> cameraDevices = QCamera::availableDevices();
QByteArray cameraDevice = cameraDevices[0];
QCamera *camera = new QCamera(cameraDevice);
camera->load();
qDebug() << "Camera status: " << camera->status();
QCameraImageCapture *imageCapture = new QCameraImageCapture(camera);
QList<QSize> resolutions = imageCapture->supportedResolutions();
@Console output: *** Camera status: 4 ***
QCamera::LoadedStatus 4
The camera is loaded and ready to be configured. This status indicates the camera device is opened and it's possible to query for supported image and video capture settings, like resolution, framerate and codecs.And although I get the status 4 (QCamera::LoadedStatus), the list of resolutions is still empty :(
PS: I made a trivial example using the same code, in case that someone else want to try it and confirm the issue: http://maefloresta.com/portal/files/sample.zip
-
I looked into Qt multimedia sources and I've found that supportedResolutions() call depends on a multimedia backend plugin of OS.
The code bellow (you can put it to the end of your main.cpp from sample.zip) shows how the call imageCapture->supportedResolutions(); is executed. It is not full trace of course, only part that is relevant to supportedResolutions.
@
QMediaObject* mediaObject = imageCapture->mediaObject();
qDebug() << "mediaObject" << mediaObject;
if (mediaObject) {
QMediaService* service = mediaObject->service();
qDebug() << "media service" << service;
if (service) {
QImageEncoderControl* encoderControl = qobject_cast<QImageEncoderControl*>(service->requestControl(QImageEncoderControl_iid));
qDebug() << "encoderControl" << encoderControl;
if (encoderControl) {
QImageEncoderSettings settings;
bool continuous = false;
qDebug() << "settings null" << settings.isNull();
QList<QSize> resolutions = encoderControl->supportedResolutions(settings, &continuous);
qDebug() << "Camera resolution list size: " << resolutions.size();
qDebug() << "settings null" << settings.isNull();
qDebug() << "continuous" << continuous;
}
}
}
@For MacOS X 10.9 it shows QImageEncoderControl is null, which means that it is not implemented.
For GNU/Linux (Ubuntu 14.04) it shows QImageEncoderControl but the list of the resolutions is still empty.The systems that have plugins and may support QImageEncoderControl::supportedResolutions are android, qnx (BlackBerry uses it too), directshow (Windows), gstreamer (GNU/Linux)
-
Just for your information... the output of my test from Windows 7 using your code. Same result, no resolutions:
Starting C:\tupi\build-sample-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\camera.exe...
Camera description: "Webcam C170"
Camera status: QCamera::UnavailableStatus
Camera resolution list size: 0
mediaObject QCamera(0x59e820)
media service DSCameraService(0x59a970)
encoderControl QObject(0x0)
C:\tupi\build-sample-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\camera.exe exited with code 0 -
Today I was running some tests from my Linux system (Ubuntu 14.04 x64). This is my report:
-
List of gstreamer dependencies installed:
http://www.maefloresta.com/tmp/gstreamer-dependencies.txt -
Using Qt 4.8 and the package qtmobility-dev the piece of code of my first post works perfectly.
@
QList<QSize> resolutions = imageCapture->supportedResolutions();
@
I got the list of resolutions for three different cameras I'm using with accurate values.
Note: The dependencies required by the package "qtmobility-dev" are:
libqtconnectivity1 libqtcontacts1 libqtfeedback1 libqtgallery1 libqtlocation1 libqtmultimediakit1 libqtorganizer1 libqtpublishsubscribe1 libqtsensors1 libqtserviceframework1 libqtsysteminfo1 libqtversit1 libqtversitorganizer1 servicefw-
Using either Qt 5.2.1 or Qt 5.3.0 and removing the package qtmobility-dev the function QCameraImageCapture::supportedResolutions() doesn't work any more.
Note: I tried two options: the Qt Ubuntu packages and the Qt online installer. -
I was checking the source code of the package qtmobility-dev running: apt-get source qtmobility-dev and comparing the structure and classes against the Qt 5.2.1/5.3.0 and I got the same code:
@
QList<QSize> QCameraImageCapture::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const
{
if (continuous)
*continuous = false;return d_func()->encoderControl ?
d_func()->encoderControl->supportedResolutions(settings, continuous) : QList<QSize>();
}
@
All the Qt versions I checked have the module "plugins/multimedia/gstreamer" included, so the problem shouldn't be there.
I tried the same test from MS Windows installing all the directshow compounds and the result is the same: an empty list.
So, what happened between Qt 4.8.x and Qt 5.2.x with this feature? Is this feature already working for someone using Qt 5.x?
-
-
Today I had the chance to test my sample from OSX and I got the same result, the method QCameraImageCapture::supportedResolutions() doesn't work here neither:
$ uname -a
Darwin MacBook-Pro.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64$ qmake -version
QMake version 3.0
Using Qt version 5.3.0 in /Users/test/Qt5.3.0/5.3/clang_64/lib$ ./camera.app/Contents/MacOS/camera
Camera description: "Cámara FaceTime HD (integrada)"
Camera status: QCamera::LoadedStatus
Camera resolution list size: 0 -
Testing the same example but this time using Qt 5.3.1 from Linux, same result:
$ ./camera
Camera description: "USB2.0 UVC WebCam"
Camera status: QCamera::LoadedStatus
CameraBinImageEncoder::supportedResolutions()
Camera resolution list size: 0The method supportedResolutions() always returns an empty list :(
-
Surprisingly I couldn't find a bug report about this (for linux)...
Now here it is:
https://bugreports.qt-project.org/browse/QTBUG-40545Follow, upvote, comment. Make some noise!
(There is a bug report for windows, but there it is just not supported...
https://bugreports.qt-project.org/browse/QTBUG-32743 ) -
It looks like that gstreamer on Linux is not returing any value in: camerabinsession.cpp
@ GstCaps *supportedCaps = 0;
g_object_get(G_OBJECT(m_camerabin),
(mode == QCamera::CaptureStillImage) ?
SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY : SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY,
&supportedCaps, NULL);
if (!supportedCaps)
return res;@I was trying calling gstreamer out of QT and was getting NULL as well. Is it a bug in GStreamer?
-
It looks like that gstreamer on Linux is not returing any value in: camerabinsession.cpp
@ GstCaps *supportedCaps = 0;
g_object_get(G_OBJECT(m_camerabin),
(mode == QCamera::CaptureStillImage) ?
SUPPORTED_IMAGE_CAPTURE_CAPS_PROPERTY : SUPPORTED_VIDEO_CAPTURE_CAPS_PROPERTY,
&supportedCaps, NULL);
if (!supportedCaps)
return res;@I was trying calling gstreamer out of QT and was getting NULL as well. Is it a bug in GStreamer?
-
Hi,
Either that or the device doesn't return the information. Do you have any other way to retrieve that information on your system ?
-
Hi,
Either that or the device doesn't return the information. Do you have any other way to retrieve that information on your system ?
-
Well, v4l2 is returning:
@$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUV 4:2:2 (YUYV)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
...@The structure GstCaps *supportedCaps from previous code, has 0 length, but it's valid but @gst_caps_is_any(supportedCaps) == true@
-
Well, v4l2 is returning:
@$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUV 4:2:2 (YUYV)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
...@The structure GstCaps *supportedCaps from previous code, has 0 length, but it's valid but @gst_caps_is_any(supportedCaps) == true@
-
I've digged deeper into GStreamer plugin gstcamerabin2.c, here it's querying for pad capabilities @pad = gst_element_get_static_pad (element, padname);
caps = gst_pad_query_caps (pad, NULL);@ and then the query failing "GstPAd.html":http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html
...gst_pad_query_caps returns all possible caps a pad can operate with, using the pad's CAPS query function, If the query fails, this function will return filter , if not NULL, otherwise ANY.
And this ANY is what's returned into QT and then returned as empty QList. I thing we should use another gstreamer input element aka v4l2src which is stable. Camerabin2 is marked as unstable and under development.
-
I've digged deeper into GStreamer plugin gstcamerabin2.c, here it's querying for pad capabilities @pad = gst_element_get_static_pad (element, padname);
caps = gst_pad_query_caps (pad, NULL);@ and then the query failing "GstPAd.html":http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPad.html
...gst_pad_query_caps returns all possible caps a pad can operate with, using the pad's CAPS query function, If the query fails, this function will return filter , if not NULL, otherwise ANY.
And this ANY is what's returned into QT and then returned as empty QList. I thing we should use another gstreamer input element aka v4l2src which is stable. Camerabin2 is marked as unstable and under development.
-
Thanks for sharing your findings !
Do you have that with gstreamer0.1 ? Did you check gstreamer 1 ?
-
Thanks for sharing your findings !
Do you have that with gstreamer0.1 ? Did you check gstreamer 1 ?