jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
547 stars 68 forks source link

Control speed of video #129

Closed Bo-M closed 4 years ago

Bo-M commented 4 years ago

Hi, I want to change speed of video every second, is that even possible? I tried to find it in documentation but no luck.

Thanks in advance!

jaseg commented 4 years ago

You can set the playback speed using the speed property. For an example where that is used, see https://github.com/jaseg/nyanping/blob/master/nyanping

Bo-M commented 4 years ago

That is what i was looking for. 👍 Is there a way to get current play speed? I ask because if i set speed to 5x, i don't know if MPV will play at that speed or is the speed lower because of hardware capability to decode video only at 3x and will play video at 3x. Is there a way to get "3x" in this case? Or is there a way to know if set speed is also the playback speed?

jaseg commented 4 years ago

Usually, that should not happen. Usually mpv will drop frames but attempt to still match the set playback speed.

I could also not find a property that straight up does what you want, but what would work (and be fairly accurate, too) would be to compare mpv's time_pos property against wall-clock time (e.g. from python's time.time()). If you take measurements periodically, you can calculate the average real playback speed:

t1_player, t1_wall = player.time_pos, time.time() time.sleep(0.5) t2_player, t2_wall = player.time_pos, time.time() actual_speed = (t2_player - t1_player) / (t2_wall - t1_wall)

Note though that this breaks when mpv loads a new file since then time_pos jumps back to 0. You might have to add some special handling for that.