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. Try to set my camera fps to 60
QtWS25 Last Chance

Try to set my camera fps to 60

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 352 Views
  • 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.
  • F Offline
    F Offline
    FullFullTwist
    wrote on 14 Nov 2024, 12:35 last edited by
    #1

    Hello,

    I try to create a little software to see my webcam and record them.

    My camera is a OBSBOT meet 2 and this camera can record to 1920*1080 at 60fps.

    But in my software, the video is in 1920*1080 but at 30 FPS and same FPS when I record.

    I've miss something?

       // Recherche de la caméra spécifiée
        for (const QCameraDevice &cameraDevice : cameras) {
            if (cameraDevice.description() == "OBSBOT Meet 2 StreamCamera") {
                camera = new QCamera(cameraDevice);
    
                // Parcourir les formats pour trouver 1920x1080 à 60 FPS
                const QList<QCameraFormat> formats = cameraDevice.videoFormats();
                bool formatFound = false;
                for (const QCameraFormat &format : formats) {
                    if (format.resolution() == QSize(1920, 1080) && format.minFrameRate() >= 60.0) {
                        camera->setCameraFormat(format);
                        qDebug() << "Format appliqué : 1920x1080 à 60 FPS";
                        formatFound = true;
                        break;
                    }
                }
                if (!formatFound) {
                    qDebug() << "Format 1920x1080 à 60 FPS non trouvé. Utilisation du format par défaut.";
                }
    
                // Configurer la session de capture
                captureSession.setCamera(camera);
                captureSession.setVideoOutput(ui->videoWidget);
    
                // Initialiser l'enregistreur
                mediaRecorder = new QMediaRecorder;
                captureSession.setRecorder(mediaRecorder);
    
                // Définir le taux d'images par seconde dans les paramètres de l'enregistreur
                QMediaRecorder::Quality quality = QMediaRecorder::VeryHighQuality;
                mediaRecorder->setQuality(quality);
                qDebug() << "Qualité d'enregistrement définie : Très haute";
    
                // Démarrer la caméra
                camera->start();
                qDebug() << "Camera démarrée avec la résolution et fréquence définies.";
                break;
            }
        }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Nov 2024, 18:14 last edited by
      #2

      Hi and welcome to devnet,

      Which version of Qt ?
      On which OS ?

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        FullFullTwist
        wrote on 14 Nov 2024, 18:25 last edited by
        #3

        Hi,

        Qt 6.8 on Windows 11

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Nov 2024, 19:31 last edited by
          #4

          What formats do you get from Qt Multimedia ?

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

          1 Reply Last reply
          0
          • F Offline
            F Offline
            FullFullTwist
            wrote on 9 Jan 2025, 12:06 last edited by
            #5

            Hello,
            Sorry for delay :)

            I've try something else, this is the new code:

            #include "MainWindow.h"
            #include <QCameraDevice>
            #include <QMediaMetaData>
            #include <QCameraFormat>
            
            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
            {
                // Setup camera and video widget
                camera = new QCamera(this);
                videoWidget = new QVideoWidget(this);
                captureSession = new QMediaCaptureSession(this);
                captureSession->setCamera(camera);
                captureSession->setVideoOutput(videoWidget);
            
                // Layout
                QVBoxLayout *layout = new QVBoxLayout;
                layout->addWidget(videoWidget);
            
                // Combobox for video formats
                formatComboBox = new QComboBox(this);
            
                // Populate the combo box with supported formats
                populateFormats();
            
                layout->addWidget(formatComboBox);
            
                // Current format label
                currentFormatLabel = new QLabel("Current Format: ", this);
                layout->addWidget(currentFormatLabel);
            
                // Connect combobox to slot
                connect(formatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::onFormatChanged);
            
                QWidget *centralWidget = new QWidget(this);
                centralWidget->setLayout(layout);
                setCentralWidget(centralWidget);
            
                // Start the camera
                camera->start();
            }
            
            MainWindow::~MainWindow()
            {
            }
            
            void MainWindow::populateFormats()
            {
                const QList<QCameraFormat> formats = camera->cameraDevice().videoFormats();
                for (const QCameraFormat &format : formats) {
                    QString formatDescription = QString("Resolution: %1x%2, Pixel Format: %3, Frame Rate: %4 fps")
                    .arg(format.resolution().width())
                        .arg(format.resolution().height())
                        .arg(format.pixelFormat())
                        .arg(format.maxFrameRate());
                    formatComboBox->addItem(formatDescription, QVariant::fromValue(format));
                }
            }
            
            void MainWindow::onFormatChanged(int index)
            {
                QCameraFormat selectedFormat = formatComboBox->currentData().value<QCameraFormat>();
                camera->setCameraFormat(selectedFormat);
                QString formatDescription = QString("Resolution: %1x%2, Pixel Format: %3, Frame Rate: %4 fps")
                                                .arg(selectedFormat.resolution().width())
                                                .arg(selectedFormat.resolution().height())
                                                .arg(selectedFormat.pixelFormat())
                                                .arg(selectedFormat.maxFrameRate());
                currentFormatLabel->setText("Current Format: " + formatDescription);
            }
            
            

            With this code, if I selected format with 60fps, nothing change, it's seems the video saty on 30 fps

            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