Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimer and Time Slider and VideoPlayer Problem
Forum Updated to NodeBB v4.3 + New Features

QTimer and Time Slider and VideoPlayer Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 701 Views 1 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.
  • D Offline
    D Offline
    DzCode
    wrote on last edited by DzCode
    #1

    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));
        });
    
    jsulmJ 1 Reply Last reply
    0
    • D 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));
          });
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      0
      • jsulmJ jsulm

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

        D Offline
        D Offline
        DzCode
        wrote on last edited by DzCode
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          2
          • SGaistS SGaist

            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.

            D Offline
            D Offline
            DzCode
            wrote on last edited by
            #5

            @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
            0

            • Login

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