0

When I use:

setNotifyInterval(1), I notice that it sometimes skips a millisecond. For example: When I print the position of the media, often it skips 2 seconds instead of 1. This is a problem because I want the program to stop every 10 seconds, and if it skips a millisecond then it won't stop.

Ex: If I want the video to stop at 10 seconds (10000 ms) it sometimes goes like this when I output the positions:

9999 ms

10001 ms

So the 10000 ms position is skipped and the video won't stop. Has anyone else had this issue before? Is it due to video buffering or computer latency? Thanks for your help.

The documentation for the method is: setNotifyInterval(milliseconds)

EDIT: I appreciate your guys help. Here is some more explanation of the example:

So I have a positionChanged signal connected to a positionChanged slot. (positionChanged method is the same name as the signal but can be changed to any other name).

Therefore, I call this to connect signal-slot mechanism: self.mediaPlayer.positionChanged.connect(self.positionChanged)

The positionChanged method tells the video to stop every 10 seconds, so it looks like this:

def positionChanged(self, position):
    if position % 10000 == 0: # 10000 milliseconds is 10 seconds
    self.mediaPlayer.pause()

Video player sometimes doesn't stop every 10 seconds. This is because setNotifyInterval(1) isn't always accurate. I will use what musicamante said and just check if it the player is greater or equal to 10 seconds. Thanks for your help

inchtown
  • 1
  • 2
  • What's `setNotifyInterval`? Please provide a [mcve]. My guess would be that the media needs to stop at the presentation time associated with a video frame in which case you can only seek 'approximately'. Just a guess though. – G.M. Feb 16 '22 at 19:05
  • Please do add more verbose details in the title and description: the context should always be clarified at the beginning of your post, the tags are only used to improve categorization and search results. – musicamante Feb 16 '22 at 19:35
  • I've edited the details to be more verbose. Thanks for your guys help. – inchtown Feb 17 '22 at 17:39

1 Answers1

0

QMediaPlayer is not intended for extremely precise playback timestamping; its purpose is to play (or record) using a high level API.

A 1ms notify interval is a bit pointless, and can ve very demanding (especially because we're talking about python, which is a terrible bottleneck); also, there is no guarantee that notifications are sent exactly every millisecond, as there is also no guarantee that the reported position will match the specific millisecond in playback. The engine tries to send notifications at the specified interval, but since the computation of the time depends on many aspects (and it requires time), some positions might be skipped, while other even repeated.
The sound buffer can be very big and video playback doesn't usually go faster than 60fps (aka one frame every ~16ms, but with standard 25fps video it's one each 40ms); you will always get an approximation of the position, and the precision depends on the underlying backend: by the time you stopped the playback, some more audio has been already added to the buffer and it will be played back anyway.

In any case, the solution is simple: instead of checking if the duration is equal to 10000, just check if it's greater than or equal to 10000.

musicamante
  • 41,230
  • 6
  • 33
  • 58