0

I have already programed an experiment using the python-vlc module, which plays my videos smoothly and in fullscreen as expected. Now I'd like to log to a file the time at each frame displayed on screen. Actually the log file comes from another machine and the logging part is solved with a simple function. What I need is access to the timing of frames actually displayed on screen. Is there a function in the module that could help on this?

2 Answers2

0

You can get the current frame time by get_time().

Check out the API documentation (https://www.olivieraubert.net/vlc/python-ctypes/doc/)

From above,

libvlc_media_player_get_time(p_mi)

Get the current movie time (in ms).

Parameters:

p_mi - the Media Player.

Returns:

the movie time (in ms), or -1 if there is no media.

Here's a simple example.

import vlc
import time

# Get VLC instance and load a video
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
media = vlc.Media("YOUR VIDEO PATH")
player.set_media(media)
player.play()
time.sleep(0.1)

# Check out the current play time periodically
while player.get_state() == vlc.State.Playing:
    t = player.get_time()
    print(t) # Treat t as you need
    time.sleep(1/120) # adjust a check out period

I usually run the above while loop part in a sub-thread and compare the previous and the current time to avoid duplicate.

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
sssbbbaaa
  • 204
  • 2
  • 12
0

The short answer is No, frames are not accessible in Vlc.
In fact you'll be lucky to get more granularity than 1/4 of a second on the time itself.
However, you can calculate a frame number based on the current playing time and the number of frames per second. Your best bet to calculate this, is function like the following:

def mspf(self):
    # Milliseconds per frame.
    return int(1000 // (self.player.get_fps() or 25))

Then based on the current playing time in seconds you can calculate an approximate frame number.

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60