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 855 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.
  • M Offline
    M Offline
    Mizmas
    wrote last edited by
    #1

    I wish QMovie had a built in function that already does this, what solutions have you come up with?

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

      Hi,

      What is your use case ?

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What is your use case ?

        M Offline
        M Offline
        Mizmas
        wrote last edited by
        #3

        @SGaist Just loading an animation with QMovie, and needing to play it in reverse. I know I could just reverse the animation file itself, but I'm more interested in having one file that I can play in both directions.

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

          The other option would be to have the file containing directly both directions.

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

          M 1 Reply Last reply
          0
          • SGaistS SGaist

            The other option would be to have the file containing directly both directions.

            M Offline
            M Offline
            Mizmas
            wrote last edited by
            #5

            @SGaist And just use jumpToFrame()? It's a good idea, still a bit tedious :D

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

              Well, in the absolute, it could work.
              One thing you can do is check the implementation of QMovie and see if you can mimic it for backward playback.

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

              M 1 Reply Last reply
              0
              • SGaistS SGaist

                Well, in the absolute, it could work.
                One thing you can do is check the implementation of QMovie and see if you can mimic it for backward playback.

                M Offline
                M Offline
                Mizmas
                wrote last edited by Mizmas
                #7

                @SGaist Here's the actual use case, It's a bit laggy though. The unselected A B C D bank indicators jump to frame 0 when a new bank is selected, I want to try to reverse the animation of the previous bank instead of jumping to 0.
                I'll try some things tomorrow

                jeremy_kJ 1 Reply Last reply
                0
                • M Mizmas

                  @SGaist Here's the actual use case, It's a bit laggy though. The unselected A B C D bank indicators jump to frame 0 when a new bank is selected, I want to try to reverse the animation of the previous bank instead of jumping to 0.
                  I'll try some things tomorrow

                  jeremy_kJ Offline
                  jeremy_kJ Offline
                  jeremy_k
                  wrote last edited by
                  #8

                  @Mizmas Have you tried setting the cache mode to CacheAll prior to running the animation forward?

                  https://doc.qt.io/qt-6/qmovie.html#cacheMode-prop:

                  Caching frames can be useful when the underlying animation format handler that QMovie relies on to decode the animation data does not support jumping to particular frames in the animation, or even "rewinding" the animation to the beginning (for looping)

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

                  M 1 Reply Last reply
                  0
                  • jeremy_kJ jeremy_k

                    @Mizmas Have you tried setting the cache mode to CacheAll prior to running the animation forward?

                    https://doc.qt.io/qt-6/qmovie.html#cacheMode-prop:

                    Caching frames can be useful when the underlying animation format handler that QMovie relies on to decode the animation data does not support jumping to particular frames in the animation, or even "rewinding" the animation to the beginning (for looping)

                    M Offline
                    M Offline
                    Mizmas
                    wrote last edited by
                    #9

                    @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 1 Reply Last reply
                    0
                    • GrecKoG Offline
                      GrecKoG Offline
                      GrecKo
                      Qt Champions 2018
                      wrote last edited by
                      #10

                      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 1 Reply Last reply
                      0
                      • 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 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 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 Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote 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 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 Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote 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 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 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 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 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 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

                                          • Login

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