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. QMediaRecorder not working - Unable to record from webcam
Forum Updated to NodeBB v4.3 + New Features

QMediaRecorder not working - Unable to record from webcam

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.5k Views 1 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.
  • S Offline
    S Offline
    Solidus
    wrote on last edited by
    #1

    Hello all.

    I've been searching everywhere for a solution to this and I've seen some threads about this problem but without a solution.

    I'm trying to record a video from two different webcams that I have on my computer. I am able to show the video for both of them but the problem is recording. When I try it nothing happens. No file is saved and the states also never change. Bellow I have attached the code that loads the cameras and the code that loads the QMediaRecorders. I also tried with just one of the cameras and it still doesn't work. The QT example "camera" does not work as well, the option for recording is always disabled.

    @void MainWindow::setCamera() {
    foreach (const QCameraInfo &cameraInfo, QCameraInfo::availableCameras()) {
    qDebug() << "Device Name: " + cameraInfo.deviceName();
    qDebug() << "Device Description: " + cameraInfo.description();
    if (cameraInfo.description() == "Integrated Camera")
    camera1 = new QCamera(cameraInfo);
    else if(cameraInfo.description() == "QuickCam for Notebooks Pro")
    camera2 = new QCamera(cameraInfo);
    }
    camera1->setViewfinder(ui->camScreen1);
    camera2->setViewfinder(ui->camScreen2);
    camera1->setCaptureMode(QCamera::CaptureVideo);
    camera2->setCaptureMode(QCamera::CaptureVideo);
    camera1->start();
    camera2->start();

    qDebug() << camera1->status();
    qDebug() << camera1->state();
    qDebug() << camera1->error();
    

    }

    void MainWindow::setVideoEncoding() {
    recorder1 = new QMediaRecorder(camera1);
    recorder2 = new QMediaRecorder(camera2);

    QVideoEncoderSettings settings = recorder1->videoSettings();
    settings.setCodec("video/mpeg2");
    settings.setQuality(QMultimedia::LowQuality);
    settings.setResolution(640,480);
    settings.setFrameRate(30.0);
    
    recorder1->setVideoSettings(settings);
    recorder2->setVideoSettings(settings);
    
    recorder1->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Record1")));
    recorder2->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Record2")));
    
    recorder1->setOutputLocation(QUrl::fromLocalFile&#40;QCoreApplication::applicationDirPath(&#41; + "/" + "testvideo1.mp4"&#41;&#41;;
    recorder2->setOutputLocation(QUrl::fromLocalFile(QCoreApplication::applicationDirPath(&#41; + "/" + "testvideo2.mp4"&#41;&#41;;
    
    qDebug(&#41; << recorder1->status();
    qDebug() << recorder1->state();
    qDebug() << recorder1->error();
    

    }@

    When I press the record button:

    @void MainWindow::toggleRecord(bool startRecord) {
    if(startRecord) {
    recorder1->record();
    recorder2->record();
    }
    else {
    recorder1->stop();
    recorder2->stop();
    }

    qDebug() << recorder1->state();
    qDebug() << recorder1->status();
    qDebug() << recorder1->error();
    
    qDebug() << recorder2->state();
    qDebug() << recorder2->status();
    qDebug() << recorder2->error();
    

    }@

    The state, status and error are as follows (every time I call them)

    Camera:
    State: QCamera::UnavailableStatus;
    Status: QCamera::ActiveState;
    Error: QCamera::NoError.

    Recorder:
    State: QMediaRecorder::UnavailableStatus;
    Status: QMediaRecorder::StoppedState;
    Error: QMediaRecorder::NoError.

    Thanks in advance for your time.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Solidus
      wrote on last edited by
      #2

      It seems the problem is that the recording is still not working for windows due to a plugin change not yet fully implemented, as explained "here":http://qt-project.org/doc/qt-5/qtmultimedia-windows.html

      I tested it on a mac and it worked fine. To fix this on windows I used the "QtMEL library":http://kibsoft.ru/.

      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