Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Camera inconsistent startup in QtMultimedia
Qt 6.11 is out! See what's new in the release blog

Camera inconsistent startup in QtMultimedia

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    munderwoods
    wrote on last edited by
    #1

    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();
    }
    
    
    SGaistS 1 Reply Last reply
    0
    • M munderwoods

      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();
      }
      
      
      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        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 ?

        M Offline
        M Offline
        munderwoods
        wrote on last edited by
        #3

        @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/input23
        

        It 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.

        M 1 Reply Last reply
        0
        • M munderwoods

          @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/input23
          

          It 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.

          M Offline
          M Offline
          munderwoods
          wrote on last edited by
          #4

          @munderwoods My camera works normally for all consumer applications btw.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            munderwoods
            wrote on last edited by
            #5

            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.

            mzimmersM 1 Reply Last reply
            0
            • M munderwoods

              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.

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              @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?

              M 1 Reply Last reply
              0
              • mzimmersM mzimmers

                @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?

                M Offline
                M Offline
                munderwoods
                wrote on last edited by
                #7

                @mzimmers If it does I definitely don't have it, but I use the camera every day with google meet, obs, etc.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved