Please nominate your Qt Champions for 2021!

[SOLVED] How to convert QVideoFrame with Format_NV21 to QImage?

  • cause the default constructor of QImage didn't support for Format_NV21
    QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format)
    switch (format) {
    case Format_Invalid:
    return QImage::Format_Invalid;
    case Format_ARGB32:
    return QImage::Format_ARGB32;
    case Format_ARGB32_Premultiplied:
    return QImage::Format_ARGB32_Premultiplied;
    case Format_RGB32:
    return QImage::Format_RGB32;
    case Format_RGB24:
    return QImage::Format_RGB888;
    case Format_RGB565:
    return QImage::Format_RGB16;
    case Format_RGB555:
    return QImage::Format_RGB555;
    case Format_ARGB8565_Premultiplied:
    return QImage::Format_ARGB8565_Premultiplied;
    case Format_BGRA32:
    case Format_BGRA32_Premultiplied:
    case Format_BGR32:
    case Format_BGR24:
    return QImage::Format_Invalid;
    case Format_BGR565:
    case Format_BGR555:
    case Format_BGRA5658_Premultiplied:
    case Format_AYUV444:
    case Format_AYUV444_Premultiplied:
    case Format_YUV444:
    case Format_YUV420P:
    case Format_YV12:
    case Format_UYVY:
    case Format_YUYV:
    case Format_NV12:
    case Format_NV21:
    case Format_IMC1:
    case Format_IMC2:
    case Format_IMC3:
    case Format_IMC4:
    case Format_Y8:
    case Format_Y16:
    case Format_Jpeg:
    case Format_CameraRaw:
    case Format_AdobeDng:
    return QImage::Format_Invalid;
    case Format_User:
    return QImage::Format_Invalid;
    return QImage::Format_Invalid;

  • I was just now looking for the same thing, quite a coincidence.

    Quick googling revealed there's NV21 -> ARGB32 conversion algorithm available in Qt sources, in "qandroidmultimediautils"; see "": I tried it and it works nicely, though a couple of points worth mentioning:

    • Nexus 5 took 30-50 ms to decode one frame (1280x960), so you may not be able to decode a video feed in real-time
    • It's LGPL if you copy the code directly to your own project. I think the header file isn't part of the public API.

Log in to reply