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. Problem with Video Recording in Qt 5.8 on Windows 10
Forum Updated to NodeBB v4.3 + New Features

Problem with Video Recording in Qt 5.8 on Windows 10

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.0k 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.
  • P Offline
    P Offline
    pj0909
    wrote on last edited by
    #1

    Hi all,

    I am new to Qt and was trying to explore the video recording through webcam with Qt but I am unable to do so. I am able to access the camera but cannot record the video. Below is my code

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        camera = new QCamera(this); //  declared in header file as QCamera *camera
        player = new QMediaPlayer(this); // declared in header file as QMediaPlayer *player
    
        videowidget = new QVideoWidget; // declared in header file as QVideoWidget *videowidget
        player->setVideoOutput(videowidget);
    
        recorder = new QMediaRecorder(camera,this); // declared in header file as QMediaRecorder *recorder
    
        QVideoEncoderSettings settings = recorder->videoSettings();
        settings.setCodec("video/mpeg2");
        settings.setResolution(1280,720);
        settings.setQuality(QMultimedia::VeryHighQuality);
        settings.setFrameRate(30.0);
        settings.setEncodingMode(QMultimedia::ConstantQualityEncoding);
        recorder->setVideoSettings(settings);
    
        camera->setCaptureMode(QCamera::CaptureVideo);
        camera->setViewfinder(ui->viewer);
        camera->start();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::on_pushButton_clicked()
    {
        if(ui->pushButton->text()==tr("Start"))
        {
            QString file = "F:/trial/Qt/VideoRecording";
            QFile file1(file);
            file1.open(QIODevice::WriteOnly);
            recorder->setContainerFormat("mpeg");
            recorder->setOutputLocation(QUrl::fromLocalFile(file));
            recorder->record();
            ui->pushButton->setText(tr("Stop"));
        }
        else
        {
            recorder->stop();
            ui->pushButton->setText(tr("Start"));
        }
    }
    

    Can anyone please guide me on my code for video recording?

    Thank you for your time and knowledge.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Check path for file.. Does subfolders exits ?
      also try to out any errors

      qDebug()<<record.state();
      qDebug()<<record.status();
      qDebug()<<record.error();

      ( note , syntax for you is recorder-> )

      P 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Check path for file.. Does subfolders exits ?
        also try to out any errors

        qDebug()<<record.state();
        qDebug()<<record.status();
        qDebug()<<record.error();

        ( note , syntax for you is recorder-> )

        P Offline
        P Offline
        pj0909
        wrote on last edited by
        #3

        @mrjj Yes, the subfolder exists. For the following code:

        qDebug()<<recorder.state();
        qDebug()<<recorder.status();
        qDebug()<<recorder.error();
        

        I get the output as:
        QMediaRecorder::StoppedState
        QMediaRecorder::UnavailableStatus
        QMediaRecorder::NoError

        I don't know how to proceed further. Can you please guide me a little bit on this.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Try to hook up the error signal
          http://doc.qt.io/qt-5/qmediarecorder.html#error

          Also
          Im not sure recording is supported in windows
          http://doc.qt.io/qt-5/qtmultimedia-windows.html
          Limitations:
          "Video recording is currently not supported" :(

          Alternatively
          http://kibsoft.ru/
          Have been suggested on SO and here in forum.
          I have no experience with it.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ronaldo
            wrote on last edited by
            #5

            Use this:

            qDebug() << recorder->isCaptureModeSupported(QCamera::CaptureVideo);
            

            In my case, it returns false. No idea what is needed in terms of hardware and/or software to turn this into true.

            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