Camera inconsistent startup in QtMultimedia
-
So this is a little weird and I'm sort of a noob so please bear with me. I need to set up a camera for capturing still images in my app. I've been using this code, just throwing it in my MainWindow now for testing purposes: https://code.qt.io/cgit/qt/qtmultimedia.git/tree/examples/multimediawidgets/camera?h=5.15
The problem is that when I first start the app with my usb camera, the light will flash for a bit then turn solid like it should be on, but there is no image displayed on the widget. However, if I stop and restart the app quickly then the light on the camera behave the same way, but the image is displayed correctly. It feels like the camera has to "warm up" and if it's allowed to get "cold" it won't work anymore. I don't know how else to describe it and I have no errors to go on. The state changes of the camera are identical either way. Can anyone help with this?
I'm on ubuntu 20, qt 5.12.8.
QActionGroup *videoDevicesGroup = new QActionGroup(this); videoDevicesGroup->setExclusive(true); const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras(); qDebug() << availableCameras; for (const QCameraInfo &cameraInfo : availableCameras) { QAction *videoDeviceAction = new QAction(cameraInfo.description(), videoDevicesGroup); videoDeviceAction->setCheckable(true); qDebug() << cameraInfo; videoDeviceAction->setData(QVariant("/dev/video0")); if (cameraInfo == QCameraInfo::defaultCamera()) videoDeviceAction->setChecked(true); qDebug() << videoDeviceAction; //ui->menuDevices->addAction(videoDeviceAction); } //connect(videoDevicesGroup, &QActionGroup::triggered, this, &Camera::updateCameraDevice); //connect(ui->captureWidget, &QTabWidget::currentChanged, this, &Camera::updateCaptureMode); setCamera(QCameraInfo::defaultCamera()); } void MainWindow::setCamera(const QCameraInfo &cameraInfo) { m_camera.reset(new QCamera(cameraInfo)); connect(m_camera.data(), &QCamera::stateChanged, this, &MainWindow::updateCameraState); connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &MainWindow::displayCameraError); // m_mediaRecorder.reset(new QMediaRecorder(m_camera.data())); // connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &MainWindow::updateRecorderState); // m_imageCapture.reset(new QCameraImageCapture(m_camera.data())); // connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &MainWindow::updateRecordTime); // connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error), // this, &MainWindow::displayRecorderError); // m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title"))); // connect(ui->exposureCompensation, &QAbstractSlider::valueChanged, this, &MainWindow::setExposureCompensation); updateCameraState(m_camera->state()); // updateLockStatus(m_camera->lockStatus(), QCamera::UserRequest); qDebug() << m_camera->lockStatus(); // updateRecorderState(m_mediaRecorder->state()); // connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &MainWindow::readyForCapture); // connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &MainWindow::processCapturedImage); // connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &MainWindow::imageSaved); // connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), // this, &MainWindow::displayCaptureError); // connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged), // this, &MainWindow::updateLockStatus); // ui->captureWidget->setTabEnabled(0, (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage))); // ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo))); qDebug() << m_camera->isCaptureModeSupported(QCamera::CaptureStillImage); qDebug() << m_camera->isCaptureModeSupported(QCamera::CaptureVideo); // updateCaptureMode(); m_camera->setCaptureMode(QCamera::CaptureStillImage); //QCameraViewfinder* viewfinder = new QCameraViewfinder(); QVideoWidget *videoWidget = new QVideoWidget; m_camera->setViewfinder(videoWidget); //m_camera->setViewfinder(viewfinder); //viewfinder->show(); videoWidget->show(); m_camera->start(); } -
So this is a little weird and I'm sort of a noob so please bear with me. I need to set up a camera for capturing still images in my app. I've been using this code, just throwing it in my MainWindow now for testing purposes: https://code.qt.io/cgit/qt/qtmultimedia.git/tree/examples/multimediawidgets/camera?h=5.15
The problem is that when I first start the app with my usb camera, the light will flash for a bit then turn solid like it should be on, but there is no image displayed on the widget. However, if I stop and restart the app quickly then the light on the camera behave the same way, but the image is displayed correctly. It feels like the camera has to "warm up" and if it's allowed to get "cold" it won't work anymore. I don't know how else to describe it and I have no errors to go on. The state changes of the camera are identical either way. Can anyone help with this?
I'm on ubuntu 20, qt 5.12.8.
QActionGroup *videoDevicesGroup = new QActionGroup(this); videoDevicesGroup->setExclusive(true); const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras(); qDebug() << availableCameras; for (const QCameraInfo &cameraInfo : availableCameras) { QAction *videoDeviceAction = new QAction(cameraInfo.description(), videoDevicesGroup); videoDeviceAction->setCheckable(true); qDebug() << cameraInfo; videoDeviceAction->setData(QVariant("/dev/video0")); if (cameraInfo == QCameraInfo::defaultCamera()) videoDeviceAction->setChecked(true); qDebug() << videoDeviceAction; //ui->menuDevices->addAction(videoDeviceAction); } //connect(videoDevicesGroup, &QActionGroup::triggered, this, &Camera::updateCameraDevice); //connect(ui->captureWidget, &QTabWidget::currentChanged, this, &Camera::updateCaptureMode); setCamera(QCameraInfo::defaultCamera()); } void MainWindow::setCamera(const QCameraInfo &cameraInfo) { m_camera.reset(new QCamera(cameraInfo)); connect(m_camera.data(), &QCamera::stateChanged, this, &MainWindow::updateCameraState); connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &MainWindow::displayCameraError); // m_mediaRecorder.reset(new QMediaRecorder(m_camera.data())); // connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &MainWindow::updateRecorderState); // m_imageCapture.reset(new QCameraImageCapture(m_camera.data())); // connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &MainWindow::updateRecordTime); // connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error), // this, &MainWindow::displayRecorderError); // m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title"))); // connect(ui->exposureCompensation, &QAbstractSlider::valueChanged, this, &MainWindow::setExposureCompensation); updateCameraState(m_camera->state()); // updateLockStatus(m_camera->lockStatus(), QCamera::UserRequest); qDebug() << m_camera->lockStatus(); // updateRecorderState(m_mediaRecorder->state()); // connect(m_imageCapture.data(), &QCameraImageCapture::readyForCaptureChanged, this, &MainWindow::readyForCapture); // connect(m_imageCapture.data(), &QCameraImageCapture::imageCaptured, this, &MainWindow::processCapturedImage); // connect(m_imageCapture.data(), &QCameraImageCapture::imageSaved, this, &MainWindow::imageSaved); // connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error), // this, &MainWindow::displayCaptureError); // connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged), // this, &MainWindow::updateLockStatus); // ui->captureWidget->setTabEnabled(0, (m_camera->isCaptureModeSupported(QCamera::CaptureStillImage))); // ui->captureWidget->setTabEnabled(1, (m_camera->isCaptureModeSupported(QCamera::CaptureVideo))); qDebug() << m_camera->isCaptureModeSupported(QCamera::CaptureStillImage); qDebug() << m_camera->isCaptureModeSupported(QCamera::CaptureVideo); // updateCaptureMode(); m_camera->setCaptureMode(QCamera::CaptureStillImage); //QCameraViewfinder* viewfinder = new QCameraViewfinder(); QVideoWidget *videoWidget = new QVideoWidget; m_camera->setViewfinder(videoWidget); //m_camera->setViewfinder(viewfinder); //viewfinder->show(); videoWidget->show(); m_camera->start(); }Hi,
Do you have the same issue if you use the Qt Camera example ?
Did you check your system logs just in case it shows something goes off with your device ? -
Hi,
Do you have the same issue if you use the Qt Camera example ?
Did you check your system logs just in case it shows something goes off with your device ?@SGaist Yeah, I just built multimedia/declarative-camera and it behaves identically.
Here is the relevant part of dmesg:
[ 8490.752069] usb 2-7: new high-speed USB device number 4 using xhci_hcd [ 8491.100177] usb 2-7: New USB device found, idVendor=046d, idProduct=0828, bcdDevice= 0.11 [ 8491.100191] usb 2-7: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 8491.101144] usb 2-7: Found UVC 1.00 device <unnamed> (046d:0828) [ 8491.230057] input: UVC Camera (046d:0828) as /devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/input/input23It seems to me like it would be something about the driver, but this should be a totally standard ubuntu install, and I just plugged in my camera to a usb 2.0 port. It's a logitech C920 I think.
-
@SGaist Yeah, I just built multimedia/declarative-camera and it behaves identically.
Here is the relevant part of dmesg:
[ 8490.752069] usb 2-7: new high-speed USB device number 4 using xhci_hcd [ 8491.100177] usb 2-7: New USB device found, idVendor=046d, idProduct=0828, bcdDevice= 0.11 [ 8491.100191] usb 2-7: New USB device strings: Mfr=0, Product=0, SerialNumber=0 [ 8491.101144] usb 2-7: Found UVC 1.00 device <unnamed> (046d:0828) [ 8491.230057] input: UVC Camera (046d:0828) as /devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/input/input23It seems to me like it would be something about the driver, but this should be a totally standard ubuntu install, and I just plugged in my camera to a usb 2.0 port. It's a logitech C920 I think.
@munderwoods My camera works normally for all consumer applications btw.
-
I've confirmed now that this isn't an issue with a different but very similar logitech camera, so I suppose that's fine... But I'd really prefer to figure out what the problem was.
-
I've confirmed now that this isn't an issue with a different but very similar logitech camera, so I suppose that's fine... But I'd really prefer to figure out what the problem was.
@munderwoods based on everything you've said, it sounds like a firmware bug in the original camera. Did that camera come with an app that you could try out, just to see how it works with that?
-
@munderwoods based on everything you've said, it sounds like a firmware bug in the original camera. Did that camera come with an app that you could try out, just to see how it works with that?
@mzimmers If it does I definitely don't have it, but I use the camera every day with google meet, obs, etc.