How to convert #39;QVideoFrame#39; with YUV data to #39;QVideoframe#39; with RGBA32 data in Qt?(如何在 Qt 中将带有 YUV 数据的“QVideoFrame转换为带有 RGBA32 数据的“QVideoframe?)
问题描述
我从网络摄像头收到 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内置的解决方案,但是不支持Qt.
具体方法如下:
- 将
QT += media-private
放入您的 qmake .pro 文件中 - 将
#include "private/qvideoframe_p.h"
放入您的代码中以使该功能可用. - 您现在可以访问具有以下签名的函数:
QImage qt_imageFromVideoFrame(const QVideoFrame &frame);
- 使用该函数将
QVideoFrame
转换为临时QImage
,然后从该图像创建输出QVideoFrame
.
这是我的示例用法:
QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat outputFormat){inputframe->map(QAbstractVideoBuffer::ReadOnly);QImage tempImage=qt_imageFromVideoFrame(inputframe);inputframe->unmap();QVideoFrame outputFrame=QVideoFrame(tempImage);返回输出帧;}
同样,从标头复制的警告内容如下:
<块引用><代码>//// 警告//-------------////这个文件不是 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.
这篇关于如何在 Qt 中将带有 YUV 数据的“QVideoFrame"转换为带有 RGBA32 数据的“QVideoframe"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Qt 中将带有 YUV 数据的“QVideoFrame"转换为带有 RGBA32 数据的“QVideoframe"?


基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01