我正在尝试录制从连接到 USB 设备的网络摄像头获取的视频。我在 Linux 64 位中使用 Qt5.1.0。
我有以下代码:
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();
当我运行此代码时,我收到以下警告和错误
CameraBin error: "Internal data flow error."
CameraBin error: "Could not negotiate format"
事实上,没有任何记录。
如果我换行
camera->setCaptureMode(QCamera::CaptureVideo);
为了
camera->setCaptureMode(QCamera::CaptureViewFinder);
没有错误输出,文件生成,但它只包含一帧(固定图像)
如果我删除这段代码:
QVideoEncoderSettings settings = recorder->videoSettings();
settings.setResolution(1280,720);
settings.setQuality(QMultimedia::VeryHighQuality);
settings.setFrameRate(30.0);
我得到两个不同的错误:
CameraBin warning: "A lot of buffers are being dropped."
CameraBin error: "Could not encode stream."
但视频实际上是录制的。