问题描述
我一直在寻找解决方案这里,我已经看到一些线程在这里关于这个问题,但没有解决方案。
I've been searching everywhere for a solution to this and I've seen some threads here about this problem but without a solution.
我正在尝试录制我在计算机上的两个不同网络摄像头的视频。我能够显示他们的视频,但问题是录音。当我尝试它没有发生。不保存文件,状态也从不改变。 Bellow我附加了加载相机的代码和加载QMediaRecorders的代码。我也试过只有一个相机,它仍然不工作。
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(QCoreApplication::applicationDirPath() + "/" + "testvide1o.mp4"));
recorder2->setOutputLocation(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + "/" + "testvideo2.mp4"));
qDebug() << recorder1->status();
qDebug() << recorder1->state();
qDebug() << recorder1->error();
}
当我按下记录按钮:
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)
相机:
州: QCamera :: UnavailableStatus;
状态: QCamera :: ActiveState;
错误: QCamera :: NoError。
记录器:
状态: QMediaRecorder :: UnavailableStatus;
状态: QMediaRecorder :: StoppedState;
错误: QMediaRecorder :: NoError。
提前感谢您的时间。
推荐答案
似乎问题是,正在解释Windows
It seems the problem is that the recording is still not working for windows, as explained here
我测试了它在一个mac它工作正常。要在Windows上修复此问题,我使用了。
I tested it on a mac a it worked fine. To fix this on windows I used the QtMEL library.
这篇关于QT的QMediaRecorder不工作 - 无法从网络摄像头录制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!