我从网络摄像头接收QVideoFrames
,它们包含YUV format (QVideoFrame::Format_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);
发布于 2017-03-30 00:35:47
我找到了一个内置在Qt5中的解决方案,但是Qt不支持。
以下是如何进行:
QT += multimedia-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);
return outputFrame;
}
同样,从标题复制的警告如下:
/W/它纯粹是作为//实现细节存在的。此头文件可能在没有通知的情况下从版本更改为//版本,甚至可以被删除。/我们是认真的。//
这在我的项目中并不重要,因为它是个人玩具产品。如果情况变得严重,我将跟踪该函数的实现,并将其复制到我的项目或其他项目中。
发布于 2017-11-29 14:44:17
我在the linked comment中找到了一个YUV -> RGB转换解决方案,
因此,实现supportedPixelFormats函数(如下面的示例所示)将甚至基于YUV的格式(在我的示例中,它将Format_YUV420P格式转换为Format_RGB24格式)具有魔力:
QList<QVideoFrame::PixelFormat>MyVideoSurface::
supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
{
Q_UNUSED(handleType);
return QList<QVideoFrame::PixelFormat>()
<< QVideoFrame::Format_RGB24
;
}
告诉我这对你有用吗。
发布于 2017-03-29 23:56:26
https://doc.qt.io/qt-5/qvideoframe.html#map
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);
}
https://stackoverflow.com/questions/43106069
复制相似问题