Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. What's a good efficient way to reverse a QMovie to play it backwards?
Forum Updated to NodeBB v4.3 + New Features

What's a good efficient way to reverse a QMovie to play it backwards?

Scheduled Pinned Locked Moved Unsolved Qt for Python
22 Posts 6 Posters 2.5k Views 3 Watching
  • 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.
  • GrecKoG GrecKo

    Unfortunately you can't set a negative speed but reading the QMovie code, calling jumpToFrame via a QTimer externally isn't that much different than what start() is doing internally.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #11

    @GrecKo
    Purely ooi for me. What kind of QTimer do you use? From my limited understanding of this stuff you need the human to see at least 50 frames per second, right? Is QTimer "accurate" and "consistent" enough to make this smooth, or does it get "lumpy" as the timeouts vary in accuracy?

    jsulmJ 1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #12

      The way it is done is to start the QTimer after each frame, with the timeout being the frame minus the time it took to process the current frame.

      1 Reply Last reply
      0
      • JonBJ JonB

        @GrecKo
        Purely ooi for me. What kind of QTimer do you use? From my limited understanding of this stuff you need the human to see at least 50 frames per second, right? Is QTimer "accurate" and "consistent" enough to make this smooth, or does it get "lumpy" as the timeouts vary in accuracy?

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #13

        @JonB said in What's a good efficient way to reverse a QMovie to play it backwards?:

        human to see at least 50 frames per second

        Smartass mode: 24 actually :-)

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #14

          OK, so does a default precision QTimer tick accurately at at least 24 per second? Not to mention that presumably if the OS is off doing something it won't, but perhaps all movie players would suffer from that issue?

          jsulmJ 1 Reply Last reply
          0
          • JonBJ JonB

            OK, so does a default precision QTimer tick accurately at at least 24 per second? Not to mention that presumably if the OS is off doing something it won't, but perhaps all movie players would suffer from that issue?

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #15

            @JonB Such low frequencies should be fine for QTimer I would say.
            https://doc.qt.io/qt-6/qt.html#TimerType-enum
            "On UNIX (including Linux, macOS, and iOS), Qt will keep millisecond accuracy for Qt::PreciseTimer.
            ...
            On Windows, Qt will use Windows's Multimedia timer facility (if available) for Qt::PreciseTimer
            "

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            JonBJ 1 Reply Last reply
            0
            • jsulmJ jsulm

              @JonB Such low frequencies should be fine for QTimer I would say.
              https://doc.qt.io/qt-6/qt.html#TimerType-enum
              "On UNIX (including Linux, macOS, and iOS), Qt will keep millisecond accuracy for Qt::PreciseTimer.
              ...
              On Windows, Qt will use Windows's Multimedia timer facility (if available) for Qt::PreciseTimer
              "

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #16

              @jsulm Indeed, that is for Qt::PreciseTimer option, which is why I was asking about the "default" mode, which is something like "coarse".

              1 Reply Last reply
              0
              • GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #17

                QMovie uses a default QTimer.

                1 Reply Last reply
                0
                • M Mizmas

                  @jeremy_k Do you mean for the laggy animation? I've tried it, but I didn't get a noticeable performance improvement. I'm using a .webp animation file though to have a full transparency channel, if I use .gif the lag is minimal, but it doesn't have full transparency, only 0 or 1

                  jeremy_kJ Offline
                  jeremy_kJ Offline
                  jeremy_k
                  wrote on last edited by
                  #18

                  @Mizmas said in What's a good efficient way to reverse a QMovie to play it backwards?:

                  @jeremy_k Do you mean for the laggy animation? I've tried it, but I didn't get a noticeable performance improvement.

                  Yes, to decrease the time required to access each frame when playing in reverse. Have you profiled the code to verify that the animation is a hotspot?

                  I'm using a .webp animation file though to have a full transparency channel, if I use .gif the lag is minimal, but it doesn't have full transparency, only 0 or 1

                  Webp uses VP8, which stores key frames and intermediate frames that modify earlier frames. Jumping to a frame may require reconstructing prior frames first.

                  Asking a question about code? http://eel.is/iso-c++/testcase/

                  M 1 Reply Last reply
                  1
                  • jeremy_kJ jeremy_k

                    @Mizmas said in What's a good efficient way to reverse a QMovie to play it backwards?:

                    @jeremy_k Do you mean for the laggy animation? I've tried it, but I didn't get a noticeable performance improvement.

                    Yes, to decrease the time required to access each frame when playing in reverse. Have you profiled the code to verify that the animation is a hotspot?

                    I'm using a .webp animation file though to have a full transparency channel, if I use .gif the lag is minimal, but it doesn't have full transparency, only 0 or 1

                    Webp uses VP8, which stores key frames and intermediate frames that modify earlier frames. Jumping to a frame may require reconstructing prior frames first.

                    M Offline
                    M Offline
                    Mizmas
                    wrote on last edited by Mizmas
                    #19

                    @jeremy_k Thanks for the help. What I did was create a minimal new .py file with only a QLabel and a QMovie to only test the animation, and the performance is exactly the same as in the video I shared before, so it seems that there was nothing bottlenecking the animation in my main app code. I'm on PyQt6 6.7.1 if that helps.
                    On the left it's opened on Chrome, and on the right PyQt6 window:

                    from PyQt6.QtWidgets import QApplication, QLabel
                    from PyQt6.QtGui import QMovie
                    import sys
                    import resources
                    
                    app = QApplication(sys.argv)
                    label = QLabel()
                    label.setStyleSheet("background: black;")
                    movie = QMovie(':/Animations/b_mode.webp')
                    movie.setCacheMode(QMovie.CacheMode.CacheAll)
                    print(movie.cacheMode())
                    print(movie.format())
                    label.setMovie(movie)
                    label.setFixedSize(50, 50)
                    label.show()
                    movie.start()
                    sys.exit(app.exec())
                    
                    1 Reply Last reply
                    0
                    • jeremy_kJ Offline
                      jeremy_kJ Offline
                      jeremy_k
                      wrote on last edited by
                      #20

                      @Mizmas Thanks for providing the POC. I gave it a quick try with a test image, but apparently my Qt installation lacks webp movie support.

                      The image on the right appears to be less smooth than the one on the left. Does it look any better if the label is allowed to assume its implicit size from the QMovie rather than being set to 50x50?

                      Asking a question about code? http://eel.is/iso-c++/testcase/

                      M 1 Reply Last reply
                      0
                      • jeremy_kJ jeremy_k

                        @Mizmas Thanks for providing the POC. I gave it a quick try with a test image, but apparently my Qt installation lacks webp movie support.

                        The image on the right appears to be less smooth than the one on the left. Does it look any better if the label is allowed to assume its implicit size from the QMovie rather than being set to 50x50?

                        M Offline
                        M Offline
                        Mizmas
                        wrote on last edited by
                        #21

                        @jeremy_k Here's an answer I got on stackoverflow: https://stackoverflow.com/questions/79672044/qmovie-is-stuttering-lagging-when-using-an-animated-webp-file-on-both-pyqt6-a/79672867#79672867

                        1 Reply Last reply
                        1
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #22

                          From the looks of it, it seems like having the animation available for both direction is the easy path.

                          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
                          1

                          • Login

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