psychopy.org | Reference | Downloads | Github

Pyglet runtime error when playing movies in psychopy 1.85.1

movies

#1

My research team has built an experiment that is a memory test on several images and sounds. It has alternating blocks of sounds and images, like this:

Sound Study (40 trials)
Sound Test (40 trials)
Image Study (40 trials)
Image Test (40 trials)

The image and sound blocks are counter-balanced, so that half of the subjects get images first and half of the subjects get sounds first.

We play videos before each of the four parts with instructions. Each video lasts for 1-2 minutes and is an mp4 file. We’re using visual.MovieStim() to play the videos. We intermittently get an error that freezes the program with the error:

File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\pyglet\media\drivers\directsound\__init__.py", line 61 in run
for player in self.players:
RuntimeError: Set changed size during iteration

We’ve run through the program a couple hundred times in the computer lab we will collect data in to try to find patterns to the crash since it is intermittent. We get it about 15% of the time. When it happens, the crash happens on trial 86 if sounds were played first (6 trials after the image test instruction video played) and on trial 43 if images were played first (3 trials after the image study instruction video played).

We commented out the call to play the videos and were able to get through the program 100 times without a crash.

Here’s the specifications of the setup we’re using
Computer lab of 25 computers using a network based user account on Windows 10
Standalone PsychoPy 1.85.1
Task built in PsychoPy coder

The code for the function to play the video is below. Any suggestions on how to fix this would be greatly appreciated.

def playMovie(filename):
    _clock = core.Clock()
    
    movie = visual.MovieStim(win=win, name='movie', filename=filename, ori=0, pos=(0,0), opacity=1, depth=0.0)
    movieLength = movie.duration #essentially, get number of frames

    #msg = visual.TextStim(win, text="Start Instructions - Press Spacebar to Continue", color="black", units="pix")
    #msg.draw()
    #win.flip()
    #event.waitKeys(keyList=["space"])
    #log.write("Starting Movie, %f\n" % core.getTime())

    #start the movie
    t = 0
    _clock.reset()
    frameN = -1
    continueRoutine = True
    endExpNow = False
    # update component parameters for each repeat
    key_resp_2 = event.BuilderKeyResponse()
    # keep track of which components have finished
    Components = [movie, key_resp_2]

    for thisComponent in Components:
        if hasattr(thisComponent, "status"):
            thisComponent.status = NOT_STARTED

    while continueRoutine:

        t = _clock.getTime()
        frameN = frameN+1 # number of completed frames (so 0 is the first frame)

        #movie updates
        if t>=0.0 and movie.status == NOT_STARTED:
            #keep track of start time/frame for later
            movie.tstart = t
            movie.frameNStart = frameN #exact frame index
            movie.setAutoDraw(True)
        frameRemains = movieLength - win.monitorFramePeriod * 0.75 #how many frames remain
        if movie.status == STARTED and t>= frameRemains:
            movie.setAutoDraw(False)
        if movie.status == FINISHED: #force-quit routine
            continueRoutine = False

        #check if all components have finished
        if not continueRoutine: # a component has requested a force-quit of routine
            break
        continueRoutine = False # will revert to True if at east one component still running
        for thisComponent in Components:
            if hasattr(thisComponent,"status") and thisComponent.status != FINISHED:
                continueRoutine = True
                break #at least one component has not yet finished

        #refresh screen
        if continueRoutine:
            win.flip()

#2

Try some of the newer movie stimulus classes, that use different backends. Start with visual.MovieStim3() and then visual.MovieStim2() and see if the problem is resolved.

This may not be obvious, as I see there is no mention of these classes in the main documentation.


#3

Thank you for the suggestion. We were able to get it working with MovieStim2.