1

QVideoFilterRunnable::run方法接收到的帧格式为 QVideoFrame::Format_NV12所以在将其加载到 GPU 纹理之前,glTexImage我需要BGRA先将其转换为。有什么办法可以改变相机的输出格式吗?

这是原始问题:

4

1 回答 1

0

由于我使用的是 QML,这是关于获取 QML 对象并在 C++ 代码中使用它的说明。我想纯 C++ 的东西会是一样的。

首先,您需要在 QML 源代码中突出显示相机对象:

Camera {
  id: camera
  objectName: "CameraObject"
}

获取 QQuickView 的根对象:

QQuickView view;

QQuickItem* root = view.rootObject();
assert(root != nullptr);

获取 QML 相机:

QObject* qmlCamera = root->findChild<QObject*>("CameraObject");
assert(qmlCamera != nullptr);

从 QML 相机对象获取 C++ 相机:

QCamera* camera = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
assert(camera != nullptr);

查找您需要的格式:

QCameraViewfinderSettings bestSetting;
assert(bestSetting.isNull()); // sanity check

auto viewfinderSettings = camera->supportedViewfinderSettings();
for (auto i: viewfinderSettings) {
  if (i.pixelFormat() != QVideoFrame::Format_ARGB32) {
    // skip non-ARGB formats
    continue;
  }
  // check i.resolution()
  // several settings with Format_ARGB32 will be available
  // pick the one with resolution which fits best for you

  bestSetting = i;
}

检查是否找到并应用设置:

assert(bestSetting.pixelFormat() == QVideoFrame::Format_ARGB32);
camera->setViewfinderSettings(bestSetting);

现在可以显示视图:

view.show();
return app.exec();
于 2015-12-16T12:38:22.747 回答