使用Qt5从USB Cam录制视频 [英] Recording Video from USB Cam with Qt5

查看:77
本文介绍了使用Qt5从USB Cam录制视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试录制从连接到USB设备的网络摄像头获取的视频.我正在Linux 64位上使用Qt5.1.0.

I am trying to record a video acquired from a webcam connect to the usb device. I am workin with Qt5.1.0 in Linux 64 bit.

我有以下代码:

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-h-m-s");
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"

实际上没有任何记录.

如果我换行

   camera->setCaptureMode(QCamera::CaptureVideo);

   camera->setCaptureMode(QCamera::CaptureViewFinder);

没有输出错误,生成了文件,但是只包含一帧(固定图像)

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

如果我删除这段代码:

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 actually recorded.

推荐答案

我在捕获图像时遇到了几乎相同的问题.我发现它只能在默认分辨率640 x 480下使用.如果将分辨率设置为较高的值,则无法使用.我还尝试了2台不同的相机,但均未成功,因此这似乎是qt5的问题.您可以尝试不设置分辨率,然后应该可以录制视频,但只能使用默认分辨率640 x 480.

I'm having almost the same problem, with capturing an image. I discovered that it is only working with the default resolution 640 x 480. If you set the resolution to a higher value it does not work. I've also tried with 2 different cameras with no success, so it seems to be a qt5 problem. You could try to don't set a resolution, then you should be able to record a video, but only with the default resolution of 640 x 480.

这篇关于使用Qt5从USB Cam录制视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆