首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Qt中将YUV数据的“QVideoframe”转换为RGBA32数据的“QVideoframe”?

如何在Qt中将YUV数据的“QVideoframe”转换为RGBA32数据的“QVideoframe”?
EN

Stack Overflow用户
提问于 2017-03-29 23:42:37
回答 3查看 4.6K关注 0票数 2

我从网络摄像头接收QVideoFrames,它们包含YUV format (QVideoFrame::Format_YUV420P)格式的图像数据。如何将这样的帧转换为QVideoFrame::Format_ARGB32QVideoFrame::Format_RGBA32的帧?

我可以不使用Qt5中现有的功能,而不进行低级别的操作吗?

示例:

代码语言:javascript
运行
复制
QVideoFrame convertFormat(const QVideoFrame &inputframe, QVideoFrame::PixelFormat outputFormat)
{
    // What comes here?
}

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

回答 3

Stack Overflow用户

发布于 2017-03-30 00:35:47

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

以下是如何进行:

  1. QT += multimedia-private放入qmake .pro文件中
  2. #include "private/qvideoframe_p.h"放入您的代码中,以使函数可用。
  3. 您现在可以访问具有以下签名的函数:QImage qt_imageFromVideoFrame(const QVideoFrame &frame);
  4. 使用该函数将QVideoFrame转换为临时QImage,然后从该映像创建输出QVideoFrame

下面是我的示例用法:

代码语言:javascript
运行
复制
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;
    }

同样,从标题复制的警告如下:

/W/它纯粹是作为//实现细节存在的。此头文件可能在没有通知的情况下从版本更改为//版本,甚至可以被删除。/我们是认真的。//

这在我的项目中并不重要,因为它是个人玩具产品。如果情况变得严重,我将跟踪该函数的实现,并将其复制到我的项目或其他项目中。

票数 3
EN

Stack Overflow用户

发布于 2017-11-29 14:44:17

我在the linked comment中找到了一个YUV -> RGB转换解决方案,

因此,实现supportedPixelFormats函数(如下面的示例所示)将甚至基于YUV的格式(在我的示例中,它将Format_YUV420P格式转换为Format_RGB24格式)具有魔力:

代码语言:javascript
运行
复制
QList<QVideoFrame::PixelFormat>MyVideoSurface::
supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
{
    Q_UNUSED(handleType);
    return QList<QVideoFrame::PixelFormat>()
        << QVideoFrame::Format_RGB24
    ;
}

告诉我这对你有用吗。

票数 1
EN

Stack Overflow用户

发布于 2017-03-29 23:56:26

https://doc.qt.io/qt-5/qvideoframe.html#map

代码语言:javascript
运行
复制
if (inputframe.map(QAbstractVideoBuffer::ReadOnly))
{
    int height = inputframe.height();
    int width = inputframe.width();
    uchar* bits = inputframe.bits();
    // figure out the inputFormat and outputFormat, they should be QImage::Format
    QImage image(bits, width, height, inputFormat);
    // do your conversion
    QImage outImage = image.convertToForma(outFormat); // blah convert
    return QVideoFrame(outImage);
}
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43106069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档