如何使用YUV数据将'QVideoFrame'转换为'QVideoframe'与Qt中的RGBA32数据? [英] How to convert 'QVideoFrame' with YUV data to 'QVideoframe' with RGBA32 data in Qt?

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

问题描述

我从网络摄像头收到 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

以下是如何操作:


  1. 放置 QT + =多媒体私有到您的qmake .pro文件中

  2. #includeprivate / qvideoframe_p.h到您的代码中,以使该功能可用。
  3. 您现在可以访问以下签名: QImage qt_imageFromVideoFrame(const QVideoFrame& frame);

  4. 使用函数将 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:

  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.

这篇关于如何使用YUV数据将'QVideoFrame'转换为'QVideoframe'与Qt中的RGBA32数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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