Python VLC - get position polling rate work arounds
Asked Answered
H

2

6

Im using Python VLC to build a custom playback app in pyqt. I have painted a nice custom slider to track along with the video, but hit a bit of an annoying problem.

No matter how often I tell my slider to update, it's quite glitchy (jumping every 1/4 second or so) and looks choppy (just the timeline, not the video).

Digging into it, I learned that

media_player.get_position()

Has quite a low polling rate. It returns the same value quite often then jumps a large amount the next time it gives a new value.

So right now I ran some test metrics and found it tends to update every 0.25-0.3 seconds. So now I have a system that basicay stores the last value and last system time a new value came in, and the last jump-distance in returned values and does some basic math with those things to fake proper linear timeline data between polls to make a very smooth timeline slider.

The problem is this assumes my value of every 0.25-0.3 seconds is consistent across machines, hardware, frame rates of videos etc.

Does anyone know of a better fix?

Maybe a way to increase the poll rate of VLC to give me better data to begin with - or some better math to handle smoothing?

Thanks

Hooked answered 25/9, 2019 at 1:51 Comment(0)
W
1

Using get_position() returns a value between 0.0 and 1.0, essentially a percentage of the current position measured against the total running time.
Instead you can use get_time() which returns the current position in 1000ths of a second.
i.e.
print (self.player.get_time()/1000) would print the current position in seconds.

You could also register a callback for the vlc event EventType.MediaPlayerTimeChanged, as mentioned in the other answer given by @mtz
i.e. Where self.player is defined as:

    self.Instance = vlc.Instance()
    self.player = self.Instance.media_player_new()

Then:

    self.vlc_event_manager = self.player.event_manager()
    self.vlc_event_manager.event_attach(vlc.EventType.MediaPlayerTimeChanged, self.media_time_changed)

def media_time_changed(self,event):
    print (event.u.new_time/1000)
    print (self.player.get_time()/1000)
    print (self.player.get_position())
Wattage answered 29/9, 2019 at 14:52 Comment(2)
Nah all of the above have the same issue. Tried it all. Get time so give me the same time for every ask within 0.3 ish seconds. Events as wellHooked
Then that is a limitation of vlc. Your remaining options are: 1. make the slider smaller and thus less sensitive to 4 updates a second; 2. opt for another media player with a finer granularity; or 3. Your current option, subtracting the time.time() from your start time using a Qtimer running at a faster rate than 4 times a second. Take a look at vlc running the same media, it isn't smooth.Wattage
A
0

Try using the libvlc_MediaPlayerPositionChanged or libvlc_MediaPlayerTimeChanged mediaplayer events instead.

https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__event.html#gga284c010ecde8abca7d3f262392f62fc6a4b6dc42c4bc2b5a29474ade1025c951d

Anemochore answered 26/9, 2019 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.