Record a video from a webcam with Qt5

亡梦爱人 提交于 2019-12-04 13:31:49

问题


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.

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?

Thanks in advance :)


回答1:


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

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!



来源:https://stackoverflow.com/questions/24841760/record-a-video-from-a-webcam-with-qt5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!