QVideoFrame bits() access too slow



  • Hello, I'am using QMediaPlayer + derived video surface with present function override. Frame mapping takes 0ms to process, but if I want access bits(), copy them into GPU memory, or just copy to another byte-bufer (created and allocated in code) it takes about 20ms on my hardware (laptop, core i5-4210M, GeForce 940M/Intel HD Graphics 4600). So 20ms is not a big time, it's ok, also tried on another PCs and laptops it's just fine. But if I'am trying to run this app on specific PC (Radeon HD7970, Core i7-4770) it takes about 2000ms, two seconds to copy bufer! If I'am trying to copy another byte-bufer (not from QVideoFrame) it's ok and takes about 2-4ms. So the problem only with mapped QVideoFrame (even if I wrapping it with QImage).

    there is an example (I've already tried to copy from videoFrame.bits(), and unmap after coping data, have no effect)

    bool QMyVideoSurface::present(const QVideoFrame &frame){
    ...
    QVideoFrame videoFrame(frame);
    
        if(videoFrame.map(QAbstractVideoBuffer::ReadWrite))
        {
            if(frame.pixelFormat() != QVideoFrame::Format_ARGB32){
                return true;
            }
    
            image = QImage(videoFrame.bits(),
                               videoFrame.width(),
                               videoFrame.height(),
                               videoFrame.bytesPerLine(), QImage::Format_ARGB32_Premultiplied);
    
            videoFrame.unmap();
    
            // bufer allocation skipped here.
    
            QElapsedTimer t;
            t.start();
    
            buf = (uchar*)image.bits();
    
            for(int i=0;i<image.byteCount();i++){
                imgBuf[i] = buf[i];
            }
    
            qDebug() << "Taken" << t.elapsed(); //shows 20ms on my laptop, and 2000ms on powerful PC
        }
    ...
    }
    

    Any suggestions are welcome. Please, help me, deadline is near.

    UDP:
    If I trying to create static bufer in .map(){} scope, e.g:

    if(videoFrame.map(QAbstractVideoBuffer::ReadWrite))
    {
    ...
       uchar abuf[4096*4096*4];
       memcpy(aib, videoFrame.bits(), videoFrame.mappedBytes());
    ...
    }
    

    then this taking about 1-2ms. But if I moving abuf declaration out of this scope (for example placing it in class definition, or in the top of file: then memcpy will take about 2000ms (actually depends on video resolution)


  • Lifetime Qt Champion

    Hi,

    Do you really need to map your video frame as ReadWrite ?

    Where do you need these data to go to ?



  • @SGaist Tried ReadOnly too. The solve is change compiler. Looks like it's MSVC2015 x64 Qt 5.6 issue, with Qt 5.2.0 MinGW x86 it works perfectly.


  • Lifetime Qt Champion

    Then it sounds like a regression… Can you check against the latest 5.7 to see if it still happens ?


Log in to reply
 

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