Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-106346

QtMultimedia uses monitor refresh rate for updating content resulting in a huge overhead

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.4.0 Beta4
    • Multimedia
    • None
    • All

    Description

      Qt will always use the frame rate of your monitor to display content. For some reason, it updates 170 times a second on my 144hz monitor, resulting in an absurd amount of gpu usage. Note this video has 25fps, but it will get refreshed 170x/second on my monitor.

       

      My quick and dirty fix for now is to call std::this_thread::sleep_for. Note FrameAnimation only works since 6.4:

      limit to 60fps:

       
      Sadly, I did not find another way to limit the fps.
       
      QML:

          FrameAnimation {
              id:fi
              running: true
      
              property real fps: smoothFrameTime > 0 ? (1.0 / smoothFrameTime) : 0
              onTriggered: {
                fl.wait(smoothFrameTime)
              }
          }
      
          Rectangle {
              anchors.fill: fpsTxt
          }
      
          Text {
              id:fpsTxt
              text: fi.fps.toFixed(0)
              font.pointSize: 24
              anchors {
                  right:parent.right
                  margins: 20
              }
          }
      

      header:

      #pragma once
      #include <QObject>
      #include <QQmlEngine>
      
      class FrameLimiter : public QObject {
          Q_OBJECT
          QML_ELEMENT
      public:
          explicit FrameLimiter(QObject* parent = nullptr);
      
          Q_INVOKABLE void wait(float smoothFrameTime);
      
      private:
          const double maxFPS = 60.0;
          const double maxPeriod = 1.0 / maxFPS;
      };
      
      

      cpp:

      void FrameLimiter::wait(float smoothFrameTime)
      {
          float wait = maxPeriod * 2 - smoothFrameTime;
          int waitMs = wait * 1000;
          //qInfo() << "waitMs: " << waitMs << "= deltaTime" << smoothFrameTime << "- maxPeriod" << maxPeriod;
          std::this_thread::sleep_for(std::chrono::milliseconds(waitMs));
      }
      
      

      I think this is a broader issue with Qt (also happens for example with custom shader that always run at maximum refresh rate), because it does not always make sense to render at full speed. Every modern game for example has the option to limit the fps if the window is no longer in focus to save power. lagocs this should be your area of expertise, right?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            kelteseth Elias Steurer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes