如何使用YUV数据将'QVideoFrame'转换为'QVideoframe'与Qt中的RGBA32数据? [英] How to convert 'QVideoFrame' with YUV data to 'QVideoframe' with RGBA32 data in Qt?
问题描述
我从网络摄像头收到 QVideoFrames
,它们包含 YUV 格式的图像数据( QVideoFrame :: Format_YUV420P
)。我怎样才能将一个这样的框架转换为
QVideoFrame :: Format_ARGB32
或 QVideoFrame :: Format_RGBA32
?
我可以在不使用低级别的情况下使用 Qt5 中的现有功能吗?
:
QVideoFrame convertFormat(const QVideoFrame& inputframe,QVideoFrame :: PixelFormat outputFormat)
{
/ /什么在这里?
}
//用法
QVideoFrame转换= convertFormat(mySourceFrame,QVideoFrame :: Format_RGB32);
Qt5 ,但 UNSUPPORTED BY QT 。
以下是如何操作:
- 放置
QT + =多媒体私有
到您的qmake .pro文件中 -
#includeprivate / qvideoframe_p.h
到您的代码中,以使该功能可用。
- 您现在可以访问以下签名:
QImage qt_imageFromVideoFrame(const QVideoFrame& frame);
- 使用函数将
QVideoFrame
添加到临时QImage
,然后从该图像创建输出QVideoFrame
li>
以下是我的示例用法:
QVideoFrame convertFormat(const QVideoFrame& inputframe,QVideoFrame :: PixelFormat outputFormat)
{
inputframe-> map(QAbstractVideoBuffer :: ReadOnly);
QImage tempImage = qt_imageFromVideoFrame(inputframe);
inputframe-> unmap();
QVideoFrame outputFrame = QVideoFrame(tempImage);
返回outputFrame;
}
同样,从标题复制的警告内容如下:
//
//警告
// -------- -----
//
//这个文件不是Qt API的一部分。它纯粹是作为
//实现细节存在的。这个头文件可能会从版本更改为
//版本,恕不另行通知,甚至被删除。
//
//我们的意思是。
//
这在我的项目中并不重要因为它是个人玩具产品。如果情况严重,我会追踪这个函数的实现,并将其复制到我的项目中。
I receive QVideoFrames
from webcam, and they contain image data in YUV format (QVideoFrame::Format_YUV420P
). How can I convert one such frame to one with QVideoFrame::Format_ARGB32
or QVideoFrame::Format_RGBA32
?
Can I do it without going low level, using just existing functionality in Qt5?
Example:
QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat outputFormat)
{
// What comes here?
}
//Usage
QVideoFrame converted = convertFormat(mySourceFrame, QVideoFrame::Format_RGB32);
I found a solution that is built into Qt5, but UNSUPPORTED BY Qt.
Here is how to go about:
- Put
QT += multimedia-private
into your qmake .pro file - Put
#include "private/qvideoframe_p.h"
into your code to make the function available. - You now have access to a function with the following signature:
QImage qt_imageFromVideoFrame(const QVideoFrame &frame);
- Use the function to convert the
QVideoFrame
to a temporayQImage
and then create the outputQVideoFrame
from that image.
Here is my example usage:
QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat outputFormat)
{
inputframe->map(QAbstractVideoBuffer::ReadOnly);
QImage tempImage=qt_imageFromVideoFrame(inputframe);
inputframe->unmap();
QVideoFrame outputFrame=QVideoFrame(tempImage);
return outputFrame;
}
Again, the warning copied from the header reads as follows:
// // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists purely as an // implementation detail. This header file may change from version to // version without notice, or even be removed. // // We mean it. //
This does not matter in my project since it is a personal toy product. If it ever gets serious I will just track down the implementation of that function and copy it into my project or something.
这篇关于如何使用YUV数据将'QVideoFrame'转换为'QVideoframe'与Qt中的RGBA32数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!