使用Qt5录制来自网络摄像头的视频 [英] Record a video from a webcam with Qt5
问题描述
我一直在努力让这个工作2天,我绝望。基本上我想用我的网络摄像头使用Qt5录制视频。我到目前为止,我可以得到一个小部件来显示网络摄像头看到什么,但由于某种原因,当我尝试用QMediaRecorder类记录它不会保存任何东西到outputLocation。
I have been trying to get this to work for 2 days now and I am desperate. Basically I want to record a video with my webcam using Qt5. I got so far that I can get a widget to display what the webcam is seeing, but for some reason whenever I try to record it with the QMediaRecorder class it doesn't save anything to the outputLocation.
创建了输出文件,但包含0个字节。我试着玩视频编解码器的设置,但仍然没有运气。我认为像这样的简单代码会工作:
The output file is created but contains 0 bytes. I have tried playing around with the settings for the video codec, but still no luck. I would think that simple code like this would work:
QCamera *camera = new QCamera(QCameraInfo::availableCameras().at(0));
QCameraViewfinder *viewFinder = new QCameraViewfinder(this);
camera->setViewfinder(viewFinder);
ui->verticalLayout->addWidget(viewFinder);
recorder = new QMediaRecorder(camera);
recorder->setOutputLocation(QUrl(QString("/home/user/test.mp4"))); // removed my name
camera->setCaptureMode(QCamera::CaptureVideo);
camera->start();
recorder->record();
我希望这基本上是为了简单录制到文件。我停止了析构函数中的记录。
I expected this to be basically it for simple recording to a file. I stopped the recording in the destructor. So, the question is, why is this not working?
提前感谢:)
推荐答案
如果你在Windows平台上,这个问题只是因为Qt不支持Windows的视频录制。请查看此 http://doc.qt.io/qt-5/ qtmultimedia-windows.html
If you are on a Windows platform this issue is simply because Qt does not support video recording for Windows. Take a look at this http://doc.qt.io/qt-5/qtmultimedia-windows.html
解决方法是使用此第三方库 https://github.com/kibsoft/QtMEL
我希望Qt尽快做到这一点。祝你好运!
A work around is to use this 3rd-party library https://github.com/kibsoft/QtMEL I hope Qt does something about this soon. Good luck!
这篇关于使用Qt5录制来自网络摄像头的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!