QMediaPlayer and QAbstractVideoSurface video frames format



  • Hello. I have code with QMediaPlayer and class derived from QAbstractVideoSurface as video output. My system is Ubuntu 15.10, and seems that underlying under QMediaPlayer streamer is gstreamer.
    The problem is, frames I get in present method is in YUV420p format, but I need RGB very much. So direct cast to RGB is very expensive - in HD video that's very slow (about 40 ms on PC in release, that's even not 25 fps), and can't find solution to get RGB for a days...
    Please help me with that.



  • @UndeadBlow Take a look at https://github.com/microsoft-mobile/mirrorhouse/blob/master/src/myvideosurface.cpp, its convertFrameData method at the end of the file might be helpful.

    Another one found from http://stackoverflow.com/questions/12469730/confusion-on-yuv-nv21-conversion-to-rgb is :

    public static void YUV_NV21_TO_RGB(int[] argb, byte[] yuv, int width, int height) {
        final int frameSize = width * height;
    
        final int ii = 0;
        final int ij = 0;
        final int di = +1;
        final int dj = +1;
    
        int a = 0;
        for (int i = 0, ci = ii; i < height; ++i, ci += di) {
            for (int j = 0, cj = ij; j < width; ++j, cj += dj) {
                int y = (0xff & ((int) yuv[ci * width + cj]));
                int v = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 0]));
                int u = (0xff & ((int) yuv[frameSize + (ci >> 1) * width + (cj & ~1) + 1]));
                y = y < 16 ? 16 : y;
    
                int r = (int) (1.164f * (y - 16) + 1.596f * (v - 128));
                int g = (int) (1.164f * (y - 16) - 0.813f * (v - 128) - 0.391f * (u - 128));
                int b = (int) (1.164f * (y - 16) + 2.018f * (u - 128));
    
                r = r < 0 ? 0 : (r > 255 ? 255 : r);
                g = g < 0 ? 0 : (g > 255 ? 255 : g);
                b = b < 0 ? 0 : (b > 255 ? 255 : b);
    
                argb[a++] = 0xff000000 | (r << 16) | (g << 8) | b;
            }
        }
    }
    


  • Yep, thank you but that is what I've talking about, in release about 40 ms on full HD frame. Better to find a way to get RGB frames, not YUV, but I don't know how that all works exactly.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.