Try to set my camera fps to 60
Unsolved
General and Desktop
-
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; } }
-
Hi and welcome to devnet,
Which version of Qt ?
On which OS ? -
Hi,
Qt 6.8 on Windows 11
-
What formats do you get from Qt Multimedia ?
-
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