C++ 如何转换';QVideoFrame';将YUV数据发送至';QVideoframe';在Qt中使用RGBA32数据?

C++ 如何转换';QVideoFrame';将YUV数据发送至';QVideoframe';在Qt中使用RGBA32数据?,c++,qt,format,qt5,qtmultimedia,C++,Qt,Format,Qt5,Qtmultimedia,我从网络摄像头接收QVideoFrame,它们包含YUV格式的图像数据(QVideoFrame::format\u YUV420P)。如何将一个这样的帧转换为具有QVideoFrame::Format_ARGB32或QVideoFrame::Format_RGBA32 我是否可以使用Qt5中现有的功能而不降低级别 例如: QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat ou

我从网络摄像头接收
QVideoFrame
,它们包含YUV格式的图像数据(
QVideoFrame::format\u YUV420P
)。如何将一个这样的帧转换为具有
QVideoFrame::Format_ARGB32
QVideoFrame::Format_RGBA32

我是否可以使用Qt5中现有的功能而不降低级别

例如:

QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat outputFormat)
{
    // What comes here?
}

//Usage
QVideoFrame converted = convertFormat(mySourceFrame, QVideoFrame::Format_RGB32);


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

以下是操作方法:

  • QT+=multimedia private
    放入qmake.pro文件中
  • #包括“private/qvideoframe\u 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);
            return outputFrame;
        }
    
    同样,从标题复制的警告内容如下:

    这在我的项目中并不重要,因为它是一个个人玩具产品。如果问题变得严重,我将跟踪该功能的实现,并将其复制到我的项目或其他地方。

    我在

    因此,像下面的示例一样实现supportedPixelFormats功能,可以将基于YUV的格式转换为格式(在我的例子中,它将格式转换为YUV420P格式):

    QList<QVideoFrame::PixelFormat>MyVideoSurface::
    supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    {
        Q_UNUSED(handleType);
        return QList<QVideoFrame::PixelFormat>()
            << QVideoFrame::Format_RGB24
        ;
    }
    
    QListMyVideoSurface::
    supportedPixelFormats(QAbstractVideoBuffer::HandleType HandleType)常量
    {
    Q_未使用(手型);
    返回QList()
    
    注意:有点相关,但QImage除外。在意识到我真正想要的是QVideoFrames中的数据转换之前,我先问了这个问题。这只是一个愚蠢的问题,因为YUV不在QImage支持的格式中,QImage图像行(位、宽度、高度、输入格式)会不会;工作?对,当我这么做的时候,我先把QVideoFrame转换成OpenCV Mat。很有趣,我写了你链接到的评论:)我还没有机会测试这个。
    //
    //  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.
    //
    
    QList<QVideoFrame::PixelFormat>MyVideoSurface::
    supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    {
        Q_UNUSED(handleType);
        return QList<QVideoFrame::PixelFormat>()
            << QVideoFrame::Format_RGB24
        ;
    }