Unsolved 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.
-
Hi
Check path for file.. Does subfolders exits ?
also try to out any errorsqDebug()<<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::NoErrorI don't know how to proceed further. Can you please guide me a little bit on this.
-
Hi
Try to hook up the error signal
http://doc.qt.io/qt-5/qmediarecorder.html#errorAlso
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. -
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 intotrue
.