Problem with Video Recording in Qt 5.8 on Windows 10



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


  • Qt Champions 2016

    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-> )



  • @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.


  • Qt Champions 2016

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.