MovieStim3 looped video lags

I’m trying to show looped videos with MovieStim3, and I have noticed that the video lags when it loops.
It probably has something to do with seek(0) at the begining of the loop - ffmpeg is slow at seeking particular frames. Is there a workaround?
Below is the code example and frame intervals plot with highlighted lags.


psychopy 2020.1.2, pyglet 1.5
Win10x64, nvidia gtx1050. Python runs on Nvidia graphics card, Vsync on

import sys
from psychopy import visual, core, event, data, gui,logging, prefs
from matplotlib import pyplot as plt

win = visual.Window(fullscr=True,
                        rgb='black',
                        size=[1920,1080],
                        winType='pyglet')

win.recordFrameIntervals = True
video = visual.MovieStim3(win, filename=r"./video.mp4", loop=True, noAudio=True)
while 1:
    if 'escape' in event.getKeys():
        win.close()
        plt.plot(win.frameIntervals, 'o')
        plt.show()
        sys.exit()
    video.draw()
    # draw other irrelevant stuff
    win.flip()

video used:
http://mirrors.standaloneinstaller.com/video-sample/jellyfish-25-mbps-hd-hevc.mp4

Hi,

Well done for providing a complete reproducible example.

Performance was much worse for me when running this on a Mac laptop with only Intel integrated graphics - the long glitches, also of about 160 ms, would occur every 104 frames, so weren’t related to the looping, but all the other regular frame durations were running long too (whereas most of yours are running well at 60 Hz).

I found that performance was markedly improved by scaling the movie down. Initially going to 720p halved the duration of the longest dropped frames, and then going to 480p finally gave me drawing of the regular frames at 60 Hz, with occasional single frame drops. You can scale the video stimulus itself back up to the window size, regardless of the source video dimensions (this doesn’t incur a noticeable performance penalty), so maybe it is worth exploring what tradeoff you can tolerate between reduced resolution and improved performance?

So, i scaled it down to 384x216, the file size went down from 31 Mb to less then three. While the timing has got somewhat better, it still loses few frames every loop.
Figure_1

Does the computer have a solid state state drive, or a spinning hard disk? If the latter, shifting to SSD can markedly reduce hardware IO bottlenecks like this.

It’s SSD. I have also tried putting videos to ramdisk, but it doesn’t seem to change anything. Requests to the disk are supposed to be cached anyway.