Please nominate your Qt Champions for 2021!

QMediaPlayer setPosition shows previous frame first

  • Hello,

    I am using QMediaPlayer to display a video and I have a step forward button that is supposed to move the video one frame forward.
    Here is the step forward function:

            def next_frame(self):
                self.progress_slider.setSliderPosition(self.progress_slider.value() + self.frame_increment_interval)
                self.player.setPosition(self.player.position() + self.frame_increment_interval)

    but when I click the button it shows a previous frame first (like 100 frames in the past) before it moves to the next frame.
    Any idea why this behaviour exists?


  • Lifetime Qt Champion


    The behaviour will depend on several factors. The video stream format, the container format, the backend you are using which depends on the OS you are on.

    The files you are playing may be highly compressed with few keyframes in between and you will not have each and every frame stored in your file. The step size also is important.

  • Oh okay. Is there a proper way to step through a video frame by frame using pyqt and without using openCV? I'd rather not have to swap back and forth between QMediaPlayer and openCV when playing the video normally and when I want to step through a video frame by frame. Also, I'm running this on Windows 10 with a mp4 video file.

Log in to reply