win.saveMovieFrames duplicates final frame when exporting mp4

I am creating short movies with win.saveMovieFrames. I’ve noticed that when saving to a movie mp4, the final frame is repeated, resulting in 1 extra frame than expected. This doesn’t happen if I output to individual png files.

Here is a minimal code example that results in a 61 frame movie instead of the intended 60 frame movie:

from psychopy import visual

win = visual.Window((500,500), fullscr = False, allowGUI=False, winType='pyglet')
dots = visual.DotStim(win, units = 'pix', nDots = 100, fieldSize = 450, speed = 2, coherence = .5, dir = 90)

for frame in range(60):
    dots.draw()
    win.flip()
    win.getMovieFrame()
win.saveMovieFrames('testMovie.mp4',fps=60, codec='libx264', clearFrames=True)

Is there anything I can do to output an mp4 video without the repeated final frame? I’m using psychopy v2023.2.3

Thank you!