psychopy.org | Reference | Downloads | Github

Repeating MovieStim3 Issues

Hi Everyone,

I’m working on trying to repeat moviestim files that I preload ahead of time. This topic has been covered before, but none of the solutions are quite working out for me.

Basically, I first create all of my movies from a file archive:

CS_Loss_Files = glob.glob(os.path.join('CS','Loss','*mp4'))
    for file in CS_Loss_Files:
        CS_Loss.append(visual.MovieStim3(win=win, filename=file, name=file,
        pos = [0,0], units = 'pix', loop = False))

Then, when I need a movie I call one randomly:

Movie = random.choice(CS_Loss)
Movie.setAutoDraw(True)
Movie.play()

Then the movie freezes on the last frame and waits for a response to continue:

while Movie.status != constants.FINISHED:
    win.flip()
    if Movie.getCurrentFrameTime() >= (Movie.duration - 0.05):
        Movie.pause()
Movie.setAutoDraw(False)

The process will then loop back and repeat randomly selecting a movie and playing it. This setup works great… for the first play of a given movie. On a second play, it either fails to actually play, has a long initial stutter, or can lead to a crash. What I’ve tried so far from searching the forums:

Suggestion: add Movie.seek(0) in the end routine section
Problem: When you go to play that movie again, there will be a very noticeable lag where the movie displays the last frame from when it was played before. The movie then resets and plays normally after about a sub 1s delay.

Suggestion: Upload duplicate movies
Problem: I already have a very high number of movies (36) that makes duplicating videos untenable.

Suggestion: Use a static period to reload the movie
Problem: There really isn’t a static period built into my experiment without causing a fairly noticeable delay. I initially had the movies load on demand one at a time, but pilot data confirmed the load time lag was noticeable and annoying.

Suggestion: use Movie.reset() in the end routine section
Problem: This solution works great shortly but a crash always inevitable occurs. I will post the log file below as it’s rather long.

Most of the forums having issues repeating MovieStims were fairly old, so I’m hoping I’ve just missed something or there has been a new development I’m unaware of to get this working as I’m out ideas.

Log following crash using Movie.reset():

Blockquote
Traceback (most recent call last):
File “Psycho_Py\GamblingTask_HalfLoad_lastrun.py”, line 760, in
Movie.setAutoDraw(True)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 583, in setAutoDraw
self.play(log=False) # set to play in case stopped
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 271, in play
self._videoClock.reset(-self.getCurrentFrameTime())
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 348, in getCurrentFrameTime
return self._nextFrameT - self.frameInterval
TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘float’
Exception ignored in: <bound method MovieStim3.del of <psychopy.visual.movie3.MovieStim3 object at 0x0000020FABD1CF98>>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 568, in del
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 545, in _unload
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py”, line 1141, in clearTextures
OSError: exception: access violation reading 0x0000000000000000
Exception ignored in: <bound method MovieStim3.del of <psychopy.visual.movie3.MovieStim3 object at 0x0000020FABD3DCF8>>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 568, in del
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 545, in _unload
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py”, line 1141, in clearTextures
OSError: exception: access violation reading 0x0000000000000000
Exception ignored in: <bound method MovieStim3.del of <psychopy.visual.movie3.MovieStim3 object at 0x0000020FABD1C6A0>>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 568, in del
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\movie3.py”, line 545, in _unload
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py”, line 1141, in clearTextures
OSError: exception: access violation reading 0x0000000000000000

I’m not sure that this is helpful but I managed to pre-load everything at the beginning.
I added this to the initial start of the task:

# Creating videos
mov_list = ['movie1','movie2','movie3','movie4','movie5',
           'movie6','movie7','movie8','movie9','movie10',
           'movie11','movie12','movie13','movie14','movie15',
           'movie16','movie17','movie18','movie19','movie20',
           'movie21','movie22','movie23','movie24','movie25',
           'movie26','movie27','movie28','movie29','movie30']
mov_id = 0

for x in mov_list:
    globals()[x]=visual.MovieStim3(win, list_stimuli[mov_id], size=None, flipVert=False, flipHoriz=False, loop=False,pos=(0.0, 0))
    mov_id += 1

And then added this on the “each frame” tab cause i wanted the movie to play after 1s (60 frames) and end before 200 frames:

if frameN > 60:
    globals()[mov_list[ind_adjust]].setAutoDraw(True)
    globals()[mov_list[ind_adjust]].play()
if frameN > 200:
    globals()[mov_list[ind_adjust]].setAutoDraw(False)
    globals()[mov_list[ind_adjust]].stop()
    continueRoutine = False

At the end of the routine I just ind_adjust += 1.

Its not the ideal solution, but currently we either do this (load every movie “by hand” in the beginning), having upwards of 30s for the task to start, or have 4-5s delays every trial when a new movie is used.
Hope it helps :confused: