Confirms single-frame stepping is reliable: monotonic frame counter across steps, and the synthetic clip's 1-frame flash event lands on exactly one frame with clean neighbors. Also documents/works around three environment quirks hit along the way: locally-built libmpv not in ldconfig's cache, QApplication resetting LC_NUMERIC and breaking libmpv's locale requirement, and the playback-restart event not firing reliably after frame-step (switched to polling estimated_frame_number).
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import locale
|
|
locale.setlocale(locale.LC_NUMERIC, "C")
|
|
import mpv
|
|
import time
|
|
from pathlib import Path
|
|
|
|
CLIP = str(Path(__file__).resolve().parent.parent / "test_media" / "sync_test_INSYNC.mp4")
|
|
|
|
m = mpv.MPV(hr_seek="yes", hr_seek_framedrop="no", keep_open="yes", pause=True, vo="null")
|
|
|
|
events_seen = []
|
|
@m.event_callback('playback-restart', 'seek', 'file-loaded')
|
|
def cb(evt):
|
|
events_seen.append(str(evt))
|
|
|
|
m.play(CLIP)
|
|
m.wait_for_property("duration", timeout=10)
|
|
m.pause = True
|
|
print("loaded, duration=", m.duration, "fps=", m.container_fps)
|
|
|
|
m.seek(4.9, reference="absolute", precision="exact")
|
|
time.sleep(0.5)
|
|
print("after seek: time_pos=", m.time_pos, "frame=", m.estimated_frame_number)
|
|
|
|
for i in range(5):
|
|
before = m.time_pos
|
|
try:
|
|
with m.prepare_and_wait_for_event('playback-restart', timeout=2.0):
|
|
m.command('frame-step')
|
|
print(f"step {i}: OK via event, time_pos={m.time_pos} frame={m.estimated_frame_number}")
|
|
except TimeoutError:
|
|
print(f"step {i}: TIMEOUT waiting for playback-restart, time_pos={m.time_pos} frame={m.estimated_frame_number} (before={before})")
|
|
|
|
m.terminate()
|