Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QTimer and Time Slider and VideoPlayer Problem

    General and Desktop
    3
    5
    237
    Loading More Posts
    • 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.
    • D
      DzCode last edited by DzCode

      Hi everyone,

      I have multiple QMediaPlayers and one time slider controlling all of them.

      To make them synchronized accrding to time slider, I am using a QTimer. However, at some point Qtimer works slow, and videos runs ahead of the timer. So that, my slider shows the wrong value.

      Is there any solution for this? The value Ihave seen in the current time label is not the same as the videos (I have a clock video). For example, in the beginning both shows 1 seconds. After a tie, video is actually in 10sec, but current time label show 9sec, also this delay between them is increasing over time.

      p_video_player_timer = new QTimer(this);
      p_video_player_timer->setInterval(25);
          connect(p_video_player_timer, &QTimer::timeout, this, [=](){
              current_video_pos_msec += 25;
              p_time_slider->blockSignals(true);
              p_time_slider->setValue(current_video_pos_msec);
              p_time_slider->blockSignals(false);
             current_time = QTime(0,0,0);
              current_time.addMSecs(current_video_pos_msec);
       p_current_time_label->setText(current_time.toString(m_TIME_FORMAT));
          });
      
      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @DzCode last edited by

        @DzCode Why don't you use https://doc.qt.io/qt-5/qmediaplayer.html#positionChanged ?

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

        D 1 Reply Last reply Reply Quote 0
        • D
          DzCode @jsulm last edited by DzCode

          @jsulm In my current implementation I am using one of the mediaplayers as a reference point and then I am using positionchanged. Also I know that I can get the precise time with that method.

          However, my customer do not want depend on any of the videos. They want me to implement a timeslider which does not depend on any of the videos.

          I tried to implement my timer in different thread, but it still creates delay. I do not know if it is possible to have precise timer. Event draging the application window also creates a delay for a separate timer

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            Video playback is more complex than that. You currently rarely have video files that contain as many images as you will see on screen (the classic 24 or 25 FPS). Depending on the video format and the parameters used to encode it you won't be able to be hyper precise on several of them in parallel parts because of that.

            You should consider testing VLC to see if you have better results with it.

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

            D 1 Reply Last reply Reply Quote 2
            • D
              DzCode @SGaist last edited by

              @SGaist Hi,

              yes, I am currently testing it with sample videos found on the Internet

              Maybe VLC can be the alternative.

              My current solution is using a thread for the timer. To eliminate the timer's wrong timeout, I am checking the QDateTime::currentDateTime(); and the time of the previous timeout signal.
              With this, I made the synchronization between my time slider and the videos. I am just tuning the slider and all videos at the moment of play button is pressed.

              It is currently working, but I do not know if it is good or bad.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post