Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVideoFrame bits() access too slow
QtWS25 Last Chance

QVideoFrame bits() access too slow

Scheduled Pinned Locked Moved Unsolved General and Desktop
qvideoframevideodecoder
4 Posts 2 Posters 2.2k Views
  • 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 Offline
    H Offline
    HAWK0044
    wrote on 6 Aug 2016, 18:58 last edited by HAWK0044 8 Jun 2016, 19:13
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Aug 2016, 23:18 last edited by
      #2

      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 7 Aug 2016, 12:22
      0
      • S SGaist
        6 Aug 2016, 23:18

        Hi,

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

        Where do you need these data to go to ?

        H Offline
        H Offline
        HAWK0044
        wrote on 7 Aug 2016, 12:22 last edited by
        #3

        @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
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Aug 2016, 19:22 last edited by
          #4

          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
          0

          4/4

          7 Aug 2016, 19:22

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved