Record video from a USB camera with Qt5

I am trying to record video received from a webcam to connect to a USB device. I am working with Qt5.1.0 on Linux 64 bit.

I have the following code:

camera = new QCamera(this); viewFinder = new QCameraViewfinder(this); camera->setViewfinder(viewFinder); recorder = new QMediaRecorder(camera,this); QVideoEncoderSettings settings = recorder->videoSettings(); settings.setResolution(1280,720); settings.setQuality(QMultimedia::VeryHighQuality); settings.setFrameRate(30.0); recorder->setVideoSettings(settings); camera->setCaptureMode(QCamera::CaptureVideo); camera->start(); QString name = filename + QDateTime::currentDateTime().toString("dd.MM.yy-hms"); recorder->setOutputLocation(QUrl::fromLocalFile(outputpath + "/" + name + ".mp4")); recorder->record(); 

When I run this code, I get the following warning and error

 CameraBin error: "Internal data flow error." CameraBin error: "Could not negotiate format" 

And actually nothing is recorded.

If I changed the line

  camera->setCaptureMode(QCamera::CaptureVideo); 

for

  camera->setCaptureMode(QCamera::CaptureViewFinder); 

The error is not output, the file is generated, but it contains only one frame (fixed image)

If I remove this piece of code:

 QVideoEncoderSettings settings = recorder->videoSettings(); settings.setResolution(1280,720); settings.setQuality(QMultimedia::VeryHighQuality); settings.setFrameRate(30.0); 

I get two different errors:

 CameraBin warning: "A lot of buffers are being dropped." CameraBin error: "Could not encode stream." 

But the video is really recorded.

+4
source share
1 answer

I have almost the same problem with image capture. I found that it only works with the default resolution of 640 x 480. If you set the resolution to a higher value, this will not work. I also tried with 2 different cameras without success, so this seems to be a qt5 problem. You can try not to set the resolution, then you should be able to record video, but only with a default resolution of 640 x 480.

+3
source

Source: https://habr.com/ru/post/1491399/


All Articles