如何为 QAbstractVideoSurface 指明支持的像素格式

How to indicate the supportedPixelFormats for QAbstractVideoSurface

我的环境:

Qt: 5.3.1 
OS: Yocto Poky 1.6.2
Device: Freescale iMX6Q
Decode: MFW_GST_V4LSINK

我正在尝试捕捉 MP4 格式视频的视频帧。 我的问题是:

  1. Windows 上的相同源代码和相同视频 运行,我获取 Format_RGB32 QVideoFrame。但是 Yocto 是 Format_YUV420P。为什么不同?
  2. 有什么办法可以让Video输出RGB彩色视频帧?
  3. QVideoFrame的格式取决于系统或视频?

我在Qt 5.9源代码中引用了这两个文件:

qvideoframeconversionhelper.cpp
qvideoframe.cpp

并找到我需要的东西

void QT_FASTCALL qt_convert_YUV420P_to_ARGB32(const QVideoFrame &frame, uchar *output)

但是5.9中的QVideoFrame与5.3不同,所以这个函数需要做一些修改:

void QT_FASTCALL qt_convert_YUV420P_to_ARGB32(const QVideoFrame &frame, uchar *output)
{
    //FETCH_INFO_TRIPLANAR(frame)  ← this's not provided in 5.3 
    // Add this ↓
    const int width = frame.width();
    const int height = frame.height();
    int yStride = frame.bytesPerLine();
    int uvStride = (frame.mappedBytes() - (yStride * height)) / height;

    const uchar *plane1 = frame.bits();
    const uchar *plane2 = plane1 + (yStride * height);
    const uchar *plane3 = plane2 + (uvStride * height / 2);
    int plane1Stride = yStride;
    int plane2Stride = uvStride;
    int plane3Stride = uvStride;
    // Add this ↑

    planarYUV420_to_ARGB32(plane1, plane1Stride,
                           plane2, plane2Stride,
                           plane3, plane3Stride,
                           1,
                           reinterpret_cast<quint32*>(output),
                           width, height);
}