仓库地址:https://gitee.com/yujinghuanqiu/qmlvideoitem
通过继承 QQuickFramebufferObject 方式,实现了一个使用 opengl 渲染视频流的 qml 组件。
视频流直接连接 newData 槽函数即可。
仅需要头文件和源文件,方便集成使用。
个人觉得还是使用 OSG 的方式会更好些,qt QQuickFramebufferObject 文档中有下面这段话仅供参考。
Warning: This class is only functional when Qt Quick is rendering via OpenGL, either directly or through the RHI-based rendering path. It is not compatible with other RHI backends, such as, Vulkan or Metal.
class MyVideo : public QQuickFramebufferObject
{
Q_OBJECT
public:
explicit MyVideo(QQuickItem *parent = nullptr);
virtual QQuickFramebufferObject::Renderer *createRenderer() const override;
QSharedPointer<Context> context();
signals:
public slots:
// 从文件加载图像
void newData(const QString &filename);
// 从内存加载图像
void newData(const QImage &image);
private:
QSharedPointer<Context> m_ctx;
};
qml 测试一张图片的显示。
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQml 2.12
import SceneGraphRender 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("QMLVideoItem")
color: "#f0f0f0"
MyVideoItem {
anchors.fill: parent
Component.onCompleted: {
newData(":/desktop.png");
}
}
}