Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QVideoFrame bits() access too slow

    General and Desktop
    qvideoframe video decoder
    2
    4
    1634
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      HAWK0044 last edited by HAWK0044

      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)

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

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

        Where do you need these data to go to ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply Reply Quote 0
        • H
          HAWK0044 @SGaist last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post