如何在 Qt 中将带有 YUV 数据的“QVideoFrame"转换为带有 RGBA32 数据的“QVideoframe"? [英] How to convert 'QVideoFrame' with YUV data to 'QVideoframe' with RGBA32 data in Qt?

查看:66
本文介绍了如何在 Qt 中将带有 YUV 数据的“QVideoFrame"转换为带有 RGBA32 数据的“QVideoframe"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从网络摄像头收到 QVideoFrames,它们包含 YUV 格式 (QVideoFrame::Format_YUV420P) 的图像数据.如何使用 QVideoFrame::Format_ARGB32QVideoFrame::Format_RGBA32 将一帧转换为一帧?

我可以不使用低级别,只使用 Qt5 中现有的功能吗?

例子:

QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat outputFormat){//什么来了?}//用法QVideoFrame 转换 = convertFormat(mySourceFrame, QVideoFrame::Format_RGB32);

解决方案

我找到了一个Qt5内置的解决方案,但是不支持Qt.

具体方法如下:

  1. QT += media-private 放入您的 qmake .pro 文件中
  2. #include "private/qvideoframe_p.h" 放入您的代码中以使该功能可用.
  3. 您现在可以访问具有以下签名的函数:QImage qt_imageFromVideoFrame(const QVideoFrame &frame);
  4. 使用该函数将 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:

  1. Put QT += multimedia-private into your qmake .pro file
  2. Put #include "private/qvideoframe_p.h" into your code to make the function available.
  3. You now have access to a function with the following signature: QImage qt_imageFromVideoFrame(const QVideoFrame &frame);
  4. Use the function to convert the QVideoFrame to a temporay QImage and then create the output QVideoFrame 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"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆