jaseg / python-mpv

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

wait_until_playing and wait_for_property throws exception #282

Closed hachpai closed 3 months ago

hachpai commented 3 months ago

Hello,

I would like to synchronize two videos on two HDMI outputs. The sync must be frame-accurate (maximum one frame of delay between the two outputs). I tried playlist and play, both are involving some frame delay. As suggested in issue #79 i tried

player1.play(video_file_1)
player2.play(video_file_2)
player1.wait_for_property('seekable')
player2.wait_for_property('seekable')
player1.seek(0, reference='absolute', precision='exact')
player1.seek(0, reference='absolute', precision='exact')

I also tried wait_until_playing() But both throw an exception after a random period of time (sometimes on the first run, sometimes after 10...)

Traceback (most recent call last):
  File "/home/mima/museum/play.py", line 35, in <module>
    player2.wait_until_playing()
  File "/home/mima/museum/mpv.py", line 995, in wait_until_playing
    self.wait_for_property('core-idle', lambda idle: not idle, timeout=timeout, catch_errors=catch_errors)
  File "/home/mima/museum/mpv.py", line 1002, in wait_for_property
    with self.prepare_and_wait_for_property(name, cond, level_sensitive, timeout=timeout, catch_errors=catch_errors) as result:
  File "/usr/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/mima/museum/mpv.py", line 1058, in prepare_and_wait_for_property
    result.set_result(rv)
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 544, in set_result
    raise InvalidStateError('{}: {!r}'.format(self._state, self))
concurrent.futures._base.InvalidStateError: FINISHED: <Future at 0x7fff54ce85d0 state=finished returned bool>

Both methods use wait for property, and the exception is always coming from there. Thank you for your help :+1:

jaseg commented 3 months ago

I was able to reproduce this, there was a bug in the implementation of level-triggered property observers. I've fixed this in master, and will push a new minor version soon.

jaseg commented 3 months ago

Thank you for the report!

jaseg commented 3 months ago

The fix is now on PyPI with version v1.0.7.